惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Security Latest
Security Latest
Recorded Future
Recorded Future
人人都是产品经理
人人都是产品经理
S
SegmentFault 最新的问题
Hacker News - Newest:
Hacker News - Newest: "LLM"
C
CXSECURITY Database RSS Feed - CXSecurity.com
博客园 - 三生石上(FineUI控件)
博客园 - 聂微东
P
Privacy & Cybersecurity Law Blog
WordPress大学
WordPress大学
Know Your Adversary
Know Your Adversary
Spread Privacy
Spread Privacy
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
量子位
L
LINUX DO - 热门话题
L
Lohrmann on Cybersecurity
博客园 - Franky
酷 壳 – CoolShell
酷 壳 – CoolShell
T
Tor Project blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
雷峰网
雷峰网
阮一峰的网络日志
阮一峰的网络日志
V
Visual Studio Blog
T
Threatpost
T
Tenable Blog
有赞技术团队
有赞技术团队
大猫的无限游戏
大猫的无限游戏
Engineering at Meta
Engineering at Meta
GbyAI
GbyAI
C
Cisco Blogs
H
Heimdal Security Blog
Attack and Defense Labs
Attack and Defense Labs
A
About on SuperTechFans
Last Week in AI
Last Week in AI
N
News and Events Feed by Topic
T
Threat Research - Cisco Blogs
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
I
Intezer
V
V2EX
Cyberwarzone
Cyberwarzone
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
B
Blog RSS Feed
V
Vulnerabilities – Threatpost
N
Netflix TechBlog - Medium
T
The Blog of Author Tim Ferriss
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
U
Unit 42
PCI Perspectives
PCI Perspectives
P
Privacy International News Feed
D
Docker

博客园 - mp3 swf

好书推荐:全世界人民都知道 下载 128码和39码编码规则 Five particular problem areas in marriage Be still 片刻停留,片刻自我 热播剧《我的兄弟叫顺溜》同名小说(全书)TXT下载 哈佛图书馆墙上的训言 C# 4.0 “修复了”死锁问题 我的团长我的团 原著小说 文字版 best way to get something done at work ORACLE 数据库调优 策略参考 oracle 存储过程的基本语法 学,无止境 Oracle 10g OCP认证资料(官方教材与考试题库)下载 美文赏析:天使降落在人间 ASP.NET 2.0实现自带TreeView的客户端连带选择 终于把ORACLE 10g的2门考试给搞结束了 功劳是老板的、钱财是子女的、身体是自己的... Oracle数据表管理建议 Oracle 10g 实例恢复Tuning
Oracle中针对层次数据所设计的专用SQL查询语句
mp3 swf · 2009-01-22 · via 博客园 - mp3 swf

假设有组织数据表orgstdstruct,其中包含UNITID,PUNITID,UNITNAME等字段,其中PUNITID是本表UNITID字段的外键,那么在ORACLE中可以通过以下语句直接查询出具有层次关系的数据,使用起来非常方便。

select level,unitid,punitid,unitname from orgstdstruct
start with punitid is null
connect by prior unitid = punitid

语法结构如下:

SELECT [LEVEL],column,expr...

FROM table

[WHERE condition(s)]

[START WITH condition(s)]

[CONNECT BY PRIOR condition(s)];

其中LEVEL字段是可选的,表示查询出来的数据层级

在Oracle 10g中,增加了一个新函数,叫做CONNECT_BY_ISLEAF,如果行的值为0表示非叶子节点,1表示叶子节点,示例如下:

select level,unitid,punitid,unitname,

(case when connect_by_isleaf=1 then '叶子' else '不是叶子' end) isleaf

from orgstdstruct
start with punitid is null
connect by prior unitid = punitid

另外,Oracle 10g还提供了CONNECT_BY_ISCYCLE和NOCYCLE关键字来解决循环问题,示例如下:

select level,connect_by_iscycle,unitid,punitid,unitname from orgstdstruct
start with punitid is null
connect by nocycly prior unitid = punitid

这样可以避免循环参加查询操作,并且通过CONNECT_BY_ISCYCLY得到哪个节点发生循环,0表示未循环,1表示循环

遗憾的是这种语法目前SQLServer还未支持,也不是标准的T-SQL语法。