一、Oracle手册

1.递归参考写法

--建立测试表数据

with temp as(
select 0 as flevel, 'a' fparent,'b' fchild,3 fqty from dual
union all select 0,'a','c',1 from dual
union all select 0,'c','d',4 from dual
union all select 0,'b','e',1 from dual
union all select 0,'b','f',4 from dual
union all select 0,'e','h',2 from dual
union all select 0,'h','k',2 from dual)

--递归运用
select length(SYS_CONNECT_BY_PATH('', '1')) AS flevel,SYS_CONNECT_BY_PATH(fparent,'\') as fparent,fchild,fqty from temp
start with fchild='e' or fchild='c'
CONNECT BY PRIOR fchild=fparent ;

--运行结果:

posted on 2016-11-17 14:23  林枫山  阅读(517)  评论(0编辑  收藏  举报