How Oracle's start with connect by prior

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.