如下结构:rule_group_id      pkg_child_id      pkg_child_parent_id
  1                     90                  1
  1                     91                  90
  1                     92                  90
  1                     93                  91
  2                     91                  2
  2                     92                  91
  2                     90                  92
  3                     94                  3
  3                     91                  94
  3                     95                  3
  3                     93                  95得到如下结果:
-1
--90
---91
----93
---92-2
--91
---92
----90-3
--94
---91
--95
---93

解决方案 »

  1.   

    CREATE OR REPLACE Procedure testb Is
    f int;begin
    f:=1;while f<=3 loop  --就1-3
    insert into testbao2  --也可以用临时表
    select level,roleid,childid,parentid from (select * from testbao --原表
    where roleid=f)a
    start with parentid=roleid 
    connect by prior childid=parentid;
    f:=f+1;
    end loop;
    end;exec testb;
    --再
    select * from testbao2我看这帖子前,oracle的递归一点不会,看了1楼的链接,再加上自己的研究,思路基本上就有了。
    lz加油。LV ROLEID CHILDID PARENTID1 1 90 1
    2 1 91 90
    3 1 93 91
    2 1 92 90
    1 2 91 2
    2 2 92 91
    3 2 90 92
    1 3 94 3
    2 3 91 94
    1 3 95 3
    2 3 93 95