17,086
社区成员
发帖
与我相关
我的任务
分享
with tab1 as (
select 1 id, null pid from dual union all
select 2 id, 1 pid from dual union all
select 3 id, 1 pid from dual union all
select 4 id, 2 pid from dual union all
select 5 id, 2 pid from dual union all
select 6 id, 3 pid from dual union all
select 7 id, 3 pid from dual
)
select connect_by_root(t1.id),
id
from tab1 t1
where t1.pid is not null
start with t1.pid is null
connect by prior t1.id = t1.pid