select level||'层',lpad(' ',(level-1)*5)||unit_nm , sys_connect_by_path(unit_nm ,'@'),unit_nm,level from sys_unit
start with unit_nm = 'unit_1'
connect by prior unit_nm = unit_relation
数据库表 sys_unit
id unit_nm unit_relation
1 unit_1
2 unit_1 _1 unit_1
3 unit_1 _2 unit_1
4 unit_1 _3 unit_1
5 unit_1 _1_1 unit_1 _1
6 unit_1 _1_2 unit_1 _1
7 unit_1 _1_1_1 unit_1 _1_1
8 unit_1 _1_1_2 unit_1 _1_1
9 unit_1 _1_1_3 unit_1 _1_1