Recursive query of Oracle PL/SQL-CONNECT BY PRIOR

Source: Internet
Author: User

Recursive query of Oracle PL/SQL-CONNECT BY PRIOR:

  1. Duzz $ scott @ orcl>SELECTEmployee_id, last_name, job_id, manager_id
  2. 2FROMEmployees
  3. 3 STARTWITHMaid = 101
  4. 4CONNECT BY PRIOREmployee_id = manager_id;
  5. (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)
  6. EMPLOYEE_ID LAST_NAME JOB_ID MANAGER_ID
  7. ----------------------------------------------------------------------------
  8. 101 Kochhar AD_VP 100
  9. 108 Greenberg FI_MGR 101
  10. 109 Faviet FI_ACCOUNT 108
  11. 110 Chen FI_ACCOUNT 108
  12. 111 Sciarra FI_ACCOUNT 108
  13. 112 Urman FI_ACCOUNT 108
  14. 113 Popp FI_ACCOUNT 108
  15. 200 Whalen AD_ASST 101
  16. 203 Mavris HR_REP 101
  17. 204 Baer PR_REP 101
  18. 205 Higgins AC_MGR 101
  19. 206 Gietz AC_ACCOUNT 205
  20. 12RowsSelected.
  21. Elapsed: 00:00:00. 03
  22. Duzz $ scott @ orcl>SELECTEmployee_id, last_name, job_id, manager_id
  23. 2FROMEmployees
  24. 3 STARTWITHMaid = 101
  25. 4CONNECT BYEmployee_id =PRIORManager_id;
  26. (Take the previous manager_id (employee_id = 101) as the current employee_id, from bottom to top)
  27. EMPLOYEE_ID LAST_NAME JOB_ID MANAGER_ID
  28. ----------------------------------------------------------------------------
  29. 101 Kochhar AD_VP 100
  30. 100 King AD_PRES
  31. Elapsed: 00:00:00. 00

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.