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

推荐订阅源

B
Blog
V
Vulnerabilities – Threatpost
Apple Machine Learning Research
Apple Machine Learning Research
V
V2EX
博客园 - 叶小钗
阮一峰的网络日志
阮一峰的网络日志
人人都是产品经理
人人都是产品经理
Latest news
Latest news
博客园 - 三生石上(FineUI控件)
美团技术团队
aimingoo的专栏
aimingoo的专栏
Google Online Security Blog
Google Online Security Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
T
Threatpost
Y
Y Combinator Blog
T
Tailwind CSS Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
A
Arctic Wolf
C
Cyber Attacks, Cyber Crime and Cyber Security
小众软件
小众软件
Recent Commits to openclaw:main
Recent Commits to openclaw:main
T
Tenable Blog
W
WeLiveSecurity
L
LINUX DO - 热门话题
D
Docker
Cyberwarzone
Cyberwarzone
量子位
A
About on SuperTechFans
The Last Watchdog
The Last Watchdog
雷峰网
雷峰网
C
CERT Recently Published Vulnerability Notes
P
Palo Alto Networks Blog
The Hacker News
The Hacker News
Blog — PlanetScale
Blog — PlanetScale
P
Proofpoint News Feed
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
F
Full Disclosure
The Cloudflare Blog
T
The Blog of Author Tim Ferriss
T
The Exploit Database - CXSecurity.com
Engineering at Meta
Engineering at Meta
O
OpenAI News
Hacker News - Newest:
Hacker News - Newest: "LLM"
Scott Helme
Scott Helme
IT之家
IT之家
S
Secure Thoughts
MongoDB | Blog
MongoDB | Blog
L
Lohrmann on Cybersecurity
博客园 - 司徒正美
Google DeepMind News
Google DeepMind News

博客园 - 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语法。