①oracle Hierarchy Query--(recursive statement)--(query tree structure)
Selectxfrom table
Start with table.col1 = ' 001 '--the root node of the qualifying statement, of course, can relax the qualification to obtain multiple root nodes, is actually more than a tree.
Onnect by Proir col1 = parent_id---previous statement col1 = parent_id of this record
When you scan a tree structure table, you need to access each node of the tree structure, one node can access only once, and the steps to access it are as follows:
The first step: starting from the root node;
The second step: access the node;
The third step: to determine whether the node has no access to the child node, if any, then to its leftmost sub-section of the left, and perform the second step, otherwise perform the fourth step;
Fourth step: If the node is the root node, the access is complete, otherwise, the fifth step;
Fifth step: Return to the parent node of the node and perform the third step.
In summary: The process of scanning the entire tree structure is also the process of traversing the tree in sequence
Learn SQL Diary (vi)