oracle 递归 省市县 过程
id parent name
1 0 广东
2 0 广西
3 1 广州
4 3 荔湾区
5 3 黄浦区
6 2 桂林
7 6 阳朔
求 一过程
输出
完成名称 子节点ID
广东\广州\荔湾区 4
广东\广州\ 黄浦区 5
广西\桂林\ 阳朔 7
------解决方案--------------------with tab as (
select '1' as id, '0'as parid, '广东' as name from dual union
select '2' as id, '0'as parid, '广西' as name from dual union
select '3' as id, '1'as parid, '广州' as name from dual union
select '4' as id, '3'as parid, '荔湾区' as name from dual union
select '5' as id, '3'as parid, '黄浦区' as name from dual union
select '6' as id, '2'as parid, '桂林' as name from dual union
select '7' as id, '6'as parid, '阳朔' as name from dual
)
select tab.id, sys_connect_by_path(tab.name, '\') from tab where level =3 connect by prior tab.id = tab.parid