Oracle树形结构查询

--遍历
select *
from treetest t
start with t.childid=1
connect by prior t.childid=t.parentid;
--上溯
select *
from treetest t
start with t.childid=7
connect by prior t.parentid=t.childid;
--树查询     
select lpad(' ',6*(level-1))||t.child,sys_connect_by_path(childid,' '),level,t.child,t.childid,t.parentid
from treetest t
start with t.childid=1
connect by prior t.childid=t.parentid;   

版权声明:本文为LGD589原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。