Vous êtes sur la page 1sur 2

**HIERARCHIAL QUERIES --A hierarchial query is a way reporting #TOP DOWN APPROACH SQL> select employee_id,last_name,job_id,manager_id from employees

start with em ployee_id=101 connect by prior employee_id=manager_id; EMPLOYEE_ID ----------101 200 203 204 205 206 108 109 110 111 112 LAST_NAME ------------------------Kochhar Whalen Mavris Baer Higgins Gietz Greenberg Faviet Chen Sciarra Urman JOB_ID MANAGER_ID ---------- ---------AD_VP 100 AD_ASST 101 HR_REP 101 PR_REP 101 AC_MGR 101 AC_ACCOUNT 205 FI_MGR 101 FI_ACCOUNT 108 FI_ACCOUNT 108 FI_ACCOUNT 108 FI_ACCOUNT 108

EMPLOYEE_ID LAST_NAME JOB_ID MANAGER_ID ----------- ------------------------- ---------- ---------113 Popp FI_ACCOUNT 108 12 rows selected. #BOTTOM UP APPROACH SQL> select employee_id,last_name,job_id,manager_id from employees start with em ployee_id=101 connect by prior manager_id=employee_id; EMPLOYEE_ID ----------101 100 LAST_NAME ------------------------Kochhar King JOB_ID MANAGER_ID ---------- ---------AD_VP 100 AD_PRES

SQL> select employee_id,last_name,job_id,manager_id from employees start with em ployee_id=200 connect by prior manager_id=employee_id; EMPLOYEE_ID ----------200 101 100 LAST_NAME ------------------------Whalen Kochhar King JOB_ID MANAGER_ID ---------- ---------AD_ASST 101 AD_VP 100 AD_PRES

SQL> select employee_id,last_name,job_id,manager_id from employees start with em ployee_id=112 connect by prior manager_id=employee_id; EMPLOYEE_ID ----------112 108 101 100 SQL> **PRUNING BRANCHES LAST_NAME ------------------------Urman Greenberg Kochhar King JOB_ID MANAGER_ID ---------- ---------FI_ACCOUNT 108 FI_MGR 101 AD_VP 100 AD_PRES

select employee_id,first_name,last_name,job_id,manager_id,level 2 from employees 3 start with manager_id is null 4 connect by prior employee_id=manager_id 5* and last_name!='Higgins'

Vous aimerez peut-être aussi