Recursive query of Oracle PL/SQL-CONNECT BY PRIOR:
- Duzz $ scott @ orcl>SELECTEmployee_id, last_name, job_id, manager_id
- 2FROMEmployees
- 3 STARTWITHMaid = 101
- 4CONNECT BY PRIOREmployee_id = manager_id;
- (PRIOR: Previous, with priority; perform recursive queries based on the previous employee_id that is equal to the row's manager_id, from top to bottom)
- EMPLOYEE_ID LAST_NAME JOB_ID MANAGER_ID
- ----------------------------------------------------------------------------
- 101 Kochhar AD_VP 100
- 108 Greenberg FI_MGR 101
- 109 Faviet FI_ACCOUNT 108
- 110 Chen FI_ACCOUNT 108
- 111 Sciarra FI_ACCOUNT 108
- 112 Urman FI_ACCOUNT 108
- 113 Popp FI_ACCOUNT 108
- 200 Whalen AD_ASST 101
- 203 Mavris HR_REP 101
- 204 Baer PR_REP 101
- 205 Higgins AC_MGR 101
- 206 Gietz AC_ACCOUNT 205
- 12RowsSelected.
- Elapsed: 00:00:00. 03
- Duzz $ scott @ orcl>SELECTEmployee_id, last_name, job_id, manager_id
- 2FROMEmployees
- 3 STARTWITHMaid = 101
- 4CONNECT BYEmployee_id =PRIORManager_id;
- (Take the previous manager_id (employee_id = 101) as the current employee_id, from bottom to top)
- EMPLOYEE_ID LAST_NAME JOB_ID MANAGER_ID
- ----------------------------------------------------------------------------
- 101 Kochhar AD_VP 100
- 100 King AD_PRES
- Elapsed: 00:00:00. 00