日期:2014-05-16 浏览次数:21681 次
with t as
(select '1' id, '2' pid, 'a' name, '1' lev
from dual
union all
select '2', '3', 'b', '2'
from dual
union all
select '3', '4', 'c', '4'
from dual
union all
select 'a', 'b', 'q1', '1'
from dual
union all
select 'b', 'c', 'e1', '3'
from dual
union all
select 'c', 'd', 'h1', '5' from dual),
t1 as
(select connect_by_root(id) id, name, lev
from t
start with lev = '1'
connect by id = prior pid)
select *
from t1 pivot(max(name) for lev in(1 level1,
2 level2,
3 level3,