1. start with 开始的id connect by prior 开始的id=父id
2. level 级别
3.实例
select * from (
select a.*,level tt from biz_district a start with district_id=8 connect by prior district_id=parent_id
) where tt=3
select a.district_id,
a.district_name,
b.district_id as district_id_1,
b.district_name as distract_name_1
from (select * from biz_district where parent_id = 8) a
left join (select *
from (select a.*, level tt
from biz_district a
start with district_id = 8
connect by prior district_id = parent_id)
where tt = 3) b
on a.district_id = b.parent_id
oracle递归查询记录
时间: 2024-10-28 20:45:55