
select level, ename, sal, job
from emp
start with ename='KING' -- 첫번째 서열을 지정
connect by prior empno = mgr; -- 여기서 empno가 부모 키, mgr이 자식 키 역할
-- 부모 키 = 자식 키
start with ...
connect by prior ...
여기서 empno와 mgr의 순서가 바뀌면 X

select rpad(' ',level*2) || ename, level, job
from emp
start with ename='KING'
connect by prior empno = mgr;
select rpad(' ', level*2) || ename, level, sal
from emp
start with ename='BLAKE'
connect by prior empno = mgr;
💡 실행순서:
from - start with - connect by - select

select rpad(' ', level*2) || ename, level, sal
from emp
where sal >= 1500
start with ename='BLAKE'
connect by prior empno = mgr;
-- 실행계획 보는 코드
SELECT * FROM table(dbms_xplan.display_cursor(null, null, 'ALLSTATS LAST'));

💡 실행순서: from - start with - connect by - where - select
설명:start with와connect by를 실행한 후에 where절이 맨 마지막에 실행됨
select level, first_name, last_name, job_id, manager_id
from hr.employees
start with manager_id is null
connect by prior employee_id = manager_id;
manager_id가 null값인 컬럼이 있어서
start with manager_id is null로 써줌