标签:style blog http io ar os sp 数据 on
SELECT ... FROM <TABLENAME> WHERE <CONDITIONAL-1> START WITH <CONDITIONAL-2> CONNECT BY <CONDITIONAL-3>
2.CONDITIONAL-2条件:是根结点的限定语句;是从哪个条件开始。
至于它们的作用;我们用下面一个例句来理解
SQL> select * from li0924; ROOT_ID ID NAME ---------- ---------- ---------- 0 1 namei --最近在看海贼王;借用下名字 1 2 lufei 1 3 shanzhi 0 4 qiaoba 3 5 suolong 4 6 luobin 6 rows selected. SQL> SELECT root_id,PRIOR ID,ID,NAME,LEVEL FROM i0924 2 START WITH root_id = 0 3 CONNECT BY root_id = PRIOR ID; --注意root_id和prior id这两列。其中level可以看作是深度 ROOT_ID PRIORID ID NAME LEVEL ---------- ---------- ---------- ---------- ---------- 0 1 namei 1 1 1 2 lufei 2 1 1 3 shanzhi 2 3 3 5 suolong 3 0 4 qiaoba 1 4 4 6 luobin 2 6 rows selected.
作用:
SQL> SELECT LEVEL FROM dual CONNECT BY LEVEL <= 10; LEVEL ---------- 1 2 3 4 5 6 7 8 9 10 10 rows selected.
【2】分割字符串
SELECT CONNECT_BY_ROOT NAME "ROOT" , 2 CONNECT_BY_ISLEAF "ISLEAF", 3 SYS_CONNECT_BY_PATH(NAME, ‘/‘) AS PATH 4 FROM li0924 5 START WITH root_id = 0 6 CONNECT BY root_id = PRIOR ID; ROOT ISLEAF PATH -------------------------------------------------------------------------------- namei 0 /namei namei 1 /namei/lufei namei 0 /namei/shanzhi namei 1 /namei/shanzhi/suolong qiaoba 0 /qiaoba qiaoba 1 /qiaoba/luobin 6 rows selected.
说说这CONNECT_BY_ROOT,CONNECT_BY_ISLEAF,SYS_CONNECT_BY_PATH,这三个函数的意义
CONNECT_BY_ROOT: 返回当前节点的最顶端节点 CONNECT_BY_ISLEAF: 判断是否为叶子节点,如果有则返回0;没有返回1 SYS_CONNECT_BY_PATH:函数显示详细路径,并用“/”分隔.其中这个分隔符可以替换。
作者 : li0924
时间 : 2014-11-20
本文版权归作者所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接.
标签:style blog http io ar os sp 数据 on
原文地址:http://www.cnblogs.com/lottu/p/4111236.html