SQL> SQL> select lpad(dept_name,lengthb(dept_name)+(level*2)-2,' ') 2 from( 3 select dept_id,dept_name,parent_dept_id 4 from s_dept_1 5 union all 6 select null,staff_name,dept_id 7 from s_dept_staff) 8 start with parent_dept_id is null 9 connect by prior dept_id = parent_dept_id;
select ename,LEVEL from emp start with ename='KING' connect by prior EMPNO=MGR
/
SQL> select * from s_dept_1;
DEPT_ID DEPT_NAME PARENT_DEPT_ID
---------- ---------- --------------
1 部门
2 部门1 1
3 部门11 2
4 部门12 2
5 部门2 1
6 部门21 5
6 rows selected
SQL> select * from s_dept_staff;
DEPT_ID STAFF_ID STAFF_NAME
---------- ---------- ----------
3 1 垃圾1
3 2 垃圾2
3 3 垃圾3
4 4 垃圾4
4 5 垃圾5
6 6 垃圾6
6 7 垃圾7
7 rows selected
SQL>
SQL> select lpad(dept_name,lengthb(dept_name)+(level*2)-2,' ')
2 from(
3 select dept_id,dept_name,parent_dept_id
4 from s_dept_1
5 union all
6 select null,staff_name,dept_id
7 from s_dept_staff)
8 start with parent_dept_id is null
9 connect by prior dept_id = parent_dept_id;
LPAD(DEPT_NAME,LENGTHB(DEPT_NA
--------------------------------------------------------------------------------
部门
部门1
部门11
垃圾1
垃圾2
垃圾3
部门12
垃圾4
垃圾5
部门2
部门21
垃圾6
垃圾7
一般都是有专门的js