Oracle PL/SQL之遞迴查詢 – CONNECT BY PRIOR

來源:互聯網
上載者:User
duzz$scott@orcl>SELECT employee_id, last_name, job_id, manager_id<br /> 2 FROM employees<br /> 3 START WITH employee_id = 101<br /> 4 CONNECT BY PRIOR employee_id=manager_id;<br />(PRIOR:先前的,優先的;按照先前的employee_id等於本行的manager_id進行遞迴查詢,從上至下)<br />EMPLOYEE_ID LAST_NAME JOB_ID MANAGER_ID<br />----------- ------------------------- ------------------------------ ----------<br /> 101 Kochhar AD_VP 100<br /> 108 Greenberg FI_MGR 101<br /> 109 Faviet FI_ACCOUNT 108<br /> 110 Chen FI_ACCOUNT 108<br /> 111 Sciarra FI_ACCOUNT 108<br /> 112 Urman FI_ACCOUNT 108<br /> 113 Popp FI_ACCOUNT 108<br /> 200 Whalen AD_ASST 101<br /> 203 Mavris HR_REP 101<br /> 204 Baer PR_REP 101<br /> 205 Higgins AC_MGR 101<br /> 206 Gietz AC_ACCOUNT 205</p><p>12 rows selected.</p><p>Elapsed: 00:00:00.03<br />duzz$scott@orcl >SELECT employee_id, last_name, job_id, manager_id<br /> 2 FROM employees<br /> 3 START WITH employee_id = 101<br /> 4 CONNECT BY employee_id= PRIOR manager_id;<br />(把先前的manager_id(employee_id = 101)作為當前的employee_id,從下至上)<br />EMPLOYEE_ID LAST_NAME JOB_ID MANAGER_ID<br />----------- ------------------------- ------------------------------ ----------<br /> 101 Kochhar AD_VP 100<br /> 100 King AD_PRES</p><p>Elapsed: 00:00:00.00<br />

 

REF:

http://www.9flex.com/archives/295/

http://www.cnblogs.com/ZHF/archive/2008/09/10/1288101.html

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.