SQL> col Manager format a15
SQL> col Employee format a15
SQL> create table emp
2 (ename varchar2(10),
3 mgr varchar2(10));
Table created.
SQL> insert into emp values('Russell','King');
1 row created.
SQL> insert into emp values('Smith','King');
1 row created.
SQL> insert into emp values('Jones','King');
1 row created.
SQL> insert into emp values('Morrison','Russell');
1 row created.
SQL> insert into emp values('Matthews','Russell');
1 row created.
SQL> insert into emp values('Pearson','Russell');
1 row created.
SQL> insert into emp values('Williams','Smith');
1 row created.
SQL> insert into emp values('Brown','Smith');
1 row created.
SQL> insert into emp values('Fielder','Brown');
1 row created.
SQL> insert into emp values('Moir','Fielder');
1 row created.
SQL> select lpad(' ',level-1)||mgr Manager,
2 lpad(' ',level-1)||ename Employee
3 from emp
4 start with mgr = 'King'
5 connect by prior ename = mgr
6 /
MANAGER EMPLOYEE
--------------- ---------------
King Russell
Russell Morrison
Russell Matthews
Russell Pearson
King Smith
Smith Williams
Smith Brown
Brown Fielder
Fielder Moir
King Jones
10 rows selected.
SQL> select lpad(' ',level-1)||mgr Manager,
2 lpad(' ',level-1)||ename Employee
3 from emp
4 start with mgr = 'King'
5 connect by prior ename = mgr
6 order siblings by ename
7 /
MANAGER EMPLOYEE
--------------- ---------------
King Jones
King Russell
Russell Matthews
Russell Morrison
Russell Pearson
King Smith
Smith Brown
Brown Fielder
Fielder Moir
Smith Williams
10 rows selected.
SQL>
No comments:
Post a Comment