关于oracle中递归取数据解析

比如有以下部门表(depts)记录信息
dept_id       dept_name             parent_id
100            a                     0
101            a1                   100
102            a2                   100
103            b                     0
104            b1                   103
105            b2                   103
106            b22                 105
有时候点一个部门时还想看到其所有的下属部门,这个在oracle里显示比较容易
如想找到部门b及其所有下属部门,可以这样
select dept_name from depts start with dept_id = 103 connect by prior dept_id= parent_id
执行后得到结果为
b
b1
b2
b22
select dept_name from depts start with dept_id = 105 connect by prior dept_id= parent_id
执行后结果为
b2
b22
在实际应用过程中dept_id当然是可以当作变量了
这些早有过,还是贴上来:)


posted @ 2008-02-21 15:55  peace  阅读(310)  评论(0编辑  收藏  举报