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

推荐订阅源

T
The Blog of Author Tim Ferriss
Know Your Adversary
Know Your Adversary
P
Palo Alto Networks Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
K
Kaspersky official blog
L
LINUX DO - 热门话题
P
Proofpoint News Feed
P
Privacy & Cybersecurity Law Blog
Google DeepMind News
Google DeepMind News
Attack and Defense Labs
Attack and Defense Labs
Cisco Talos Blog
Cisco Talos Blog
AI
AI
L
LINUX DO - 最新话题
H
Heimdal Security Blog
Hacker News: Ask HN
Hacker News: Ask HN
Webroot Blog
Webroot Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
The GitHub Blog
The GitHub Blog
I
Intezer
Blog — PlanetScale
Blog — PlanetScale
有赞技术团队
有赞技术团队
S
Securelist
博客园_首页
IT之家
IT之家
Schneier on Security
Schneier on Security
博客园 - 叶小钗
罗磊的独立博客
WordPress大学
WordPress大学
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
MongoDB | Blog
MongoDB | Blog
P
Proofpoint News Feed
阮一峰的网络日志
阮一峰的网络日志
A
Arctic Wolf
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
W
WeLiveSecurity
The Register - Security
The Register - Security
D
DataBreaches.Net
S
Security @ Cisco Blogs
Security Archives - TechRepublic
Security Archives - TechRepublic
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
腾讯CDC
Recorded Future
Recorded Future
NISL@THU
NISL@THU
N
News and Events Feed by Topic
T
Tailwind CSS Blog
N
News and Events Feed by Topic
Cyberwarzone
Cyberwarzone
T
Tor Project blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com

博客园 - I Believe

哲理 Win PE(帮老马研究下) TCP/IP协议基础 Gis基础知识 javascript和jscript的区别 javascript常用代码大全(转贴) - I Believe - 博客园 三维场景中的实时动态云彩绘制方法 正则表达式 名言 div和span 面向对象 window.event.srcElement document.all HTML语言的发展 C/S和B/S 微软Visual Studio2005开发工具路线图详解 (转发) 空间坐标系统的种类 OLE和activex 励志篇(程序员)
connect by prior
I Believe · 2008-09-05 · via 博客园 - I Believe

connect by prior start with 经常会被用到一个表中存在递归关系的时候。比如我们经常会将一个比较复杂的目录树存储到一个表中。或者将一些部门存储到一个表中,而这些部门互相有隶属关系。这个时候你就会用到connect by prior start with。

典型的使用方法就是:
select * from table connect by prior cur_id=parent_id start with cur_id=???
例如:
a            b
1           0
2           1
3           1
4           2
5           3

如果想查找a=2及其下面的所有数据,则:
select * from table connect by prior a=b start with a=2
a           b
2           1
4           2

这些只是基础,皮毛。其实只要你灵活的构造查询语句。可以得出意想不到的结果。比如生成树每一个路径。
但是这些记录组成的树必须正常才可以。如果有互为父子的情况,就会出现循环错误!

select * from tb_cus_area_cde

--子取父
select * from tb_cus_area_cde a    
CONNECT BY PRIOR     a.c_snr_area=a.c_area_cde START WITH a.c_area_cde='1040101'

--父取子
select * from tb_cus_area_cde a    
CONNECT BY PRIOR     a.c_area_cde=a.c_snr_area START WITH a.c_snr_area is null

注意:在用这个函数的时候,statement的参数要用 ResultSet.TYPE_SCROLL_INSENSITIVE   而不能用 ResultSet.TYPE_SCROLL_SENSITIVE,在这里再把这两个之间的区别讲讲:

1.TYPE_FORWORD_ONLY,只可向前滚动;   
    
2.TYPE_SCROLL_INSENSITIVE,双向滚动,但不及时更新,就是如果数据库里的数据修改过,并不在ResultSet中反应出来。   
    
3.TYPE_SCROLL_SENSITIVE,双向滚动,并及时跟踪数据库的更新,以便更改ResultSet中的数据