Oracle's start with connect by Prior is based on the conditional recursive query "tree", divided into four types of usage:
First type: Start with child node id= ' ... ' Connect by prior child Node ID = parent Node ID
SELECT * FROM Mdm_organization o start with o.org_code= ' 10000008 ' Connect by prior O.org_code=o.org_parent_code
According to the condition org_code= ' 10000008 ', the ' 10000008 ' (including itself) and its child nodes are recursively queried, the results are as follows
the query results itself for all descendant nodes (including itself).
Second type: Start with child node id= ' ... ' Connect by child Node ID = Prior parent node ID
SELECT * FROM Mdm_organization o start with o.org_code= ' 10000008 ' Connect by O.org_code=prior O.org_parent_code
According to the condition org_code= ' 10000008 ', the ' 10000008 ' (including itself) and its parent node are recursively queried, the results are as follows
Query results for all of your previous generation nodes (including yourself).
Third type: Start with parent node id= ' ... ' Connect by prior child Node ID = parent Node ID
SELECT * FROM Mdm_organization o start with o.org_parent_code= ' 10000008 ' Connect by prior O.org_code=o.org_parent_code
According to the conditions org_parent_code= ' 10000008 ', the ' 10000008 ' (not including their own) sub-node recursive query, the results are as follows
The query results itself for all descendant nodes (not including itself).
Fourth type: Start with parent node id= ' ... ' Connect by child Node ID = Prior parent node ID
SELECT * FROM Mdm_organization o start with o.org_parent_code= ' 10000008 ' connect by O.org_code = Prior O.org_parent_code
According to the conditions org_parent_code= ' 10000008 ', the first generation of ' 10000008 ' (including their own) children and their parent nodes are recursively queried, the results are as follows
The query results its own first-generation post-node and all previous-generation nodes (including themselves).
If there is a where condition, the following
SELECT * FROM Mdm_organization o where condition start with o.org_parent_code= ' 10000008 ' connect by O.org_code = Prior O.org_pare Nt_code
The order of execution is to perform the start with connect by prior first, and then filter by the Where condition.
How Oracle's start with connect by prior