Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Tree structure and hierarchical query in oracle Table

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

1. Here, take the emp table as an example. There is a subordinate-superior relationship between the empno field and the mgr field in this table.

2 look up the top boss from top to bottom, where the level is one of the three pseudo columns

Select level,empno,ename,mgr from emp

Start with empno=7839-subordinate field

Connect by prior empno=mgr;-- subordinate field = superior field

3 check from bottom to top

Select level,empno,ename,mgr from emp

Start with empno=7369-subordinate field

Connect by prior mgr=empno;-- parent field = subordinate field

4-- just filter a single node. Everything under that node is preserved.

Select level,empno,ename,mgr from emp

Where empno7698-subordinate field

Start with empno=7839

Connect by prior empno=mgr;-- subordinate field = superior field

5-filter the entire branch

Select level,empno,ename,mgr from emp

Start with empno=7839-subordinate field

Connect by prior empno=mgr and empno7698;-- subordinate field = superior field

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report