Tree structure and hierarchical query in oracle Table
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