The child node is traced to the root node.
SELECT * from persons.dept start with deptid=76 connect by prior Paredeptid=deptid
Traverse the child nodes (without the root node) through the root node.
SELECT * from persons.dept start with Paredeptid=0 connect by prior Deptid=paredeptid
Traverse a child node (containing the root node) through the root node.
SELECT * from persons.dept start with Deptid=0 connect by prior Deptid=paredeptid
The level keyword allows you to query your hierarchy.
Select A.*,level from Persons.dept a start with Paredeptid=0 connect by prior Deptid=paredeptid
Note:
Start with the use of Connect by, the start with behind is the seed of recursion.
The seed of recursion is the place where the recursion begins. The "prior" in the back of connect by is the default: it can only query the starting line that matches the condition, and does not make a recursive query;
The fields that are placed behind connect by prior are related and indicate the direction of the query.
Exercise: Get the top node from a child node
Select First_value (DeptID) over (ORDER by level DESC ROWS unbounded preceding) as Firstdeptid from persons.dept start with Deptid=76 Connect by Prior Paredeptid=deptid
Table structure
DeptID Paredeptid NAME
Number number CHAR (+ Byte)
Department ID parent Department ID (owning Department ID) Department name
Oracle Recursive query child nodes