oracle树结构查询

1.根据父节点递归查询所有子节点

SELECT distinct LPAD('',2*(LEVEL - 1),'')||ORGCODE AS organCode,

  PARENT_CODE AS panrentCode

  FROM t_organ

  START WITH ORGCODE =父节点编码

  CONNECT BY PARENT_CODE = PRIOR ORGCODE ;

2.根据子节点递归查询所有父节点

 

SELECT distinct LPAD('',2*(LEVEL - 1),'')||ORGCODE AS organCode,

 

  PARENT_CODE AS panrentCode

 

  FROM t_organ

 

  START WITH ORGCODE =父节点编码

 

  CONNECT BY PRIOR PARENT_CODE =  ORGCODE ;

 

posted @ 2015-01-19 13:55  java学习之旅  阅读(427)  评论(0编辑  收藏  举报