递归写法参考

--递归参考写法

--建立测试表数据

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 ;

--运行结果:

你可能感兴趣的:(递归写法参考)