日期:2014-05-16 浏览次数:20845 次
SQL> WITH t as (
2 select 'A' id, 'P' pid from dual union all
3 select 'B' id, 'P' pid from dual union all
4 select 'A1' id, 'A' pid from dual union all
5 select 'A2' id, 'A' pid from dual union all
6 select 'A3' id, 'A' pid from dual union all
7 select 'B1' id, 'B' pid from dual union all
8 select 'B2' id, 'B' pid from dual union all
9 select 'B11' id, 'B1' pid from dual union all
10 select 'B12' id, 'B1' pid from dual union all
11 select 'B111' id, 'B11' pid from dual )
12 select 'P'
------解决方案--------------------
SYS_CONNECT_BY_PATH(ID,'/') from t start with pid = 'P' connect by PRIOR id = pid;
'P'
------解决方案--------------------
SYS_CONNECT_BY_PATH(ID,'/
--------------------------------------------------------------------------------
P/A
P/A/A1
P/A/A2
P/A/A3
P/B
P/B/B1
P/B/B1/B11
P/B/B1/B11/B111
P/B/B1