Oracle recursive operations (Tree operations) start with org_id = '1' connect by prior paren

Source: Internet
Author: User


Oracle recursive operations (Tree operations) start with org_id = '1' connect by prior parent_id = son_id 1. preface oracle recursive operations are often used in the directory structure on our web pages. It is said that they are frequently asked questions during interviews, and some online things are not very clear, so I sorted it out myself. The following mainly uses an example to illustrate how to directly copy the code and run it. Www.2cto.com 2. start with org_id = 'condition 1' prior parent_id = son_id; this is used to retrieve all the tree structures and store the tree directories in the same table, such as 1 | -- 2 | -- 3 | -- 4 | -- 5 | -- 6 | -- 7 | -- 8 | -- 9 | -- 10 www.2cto.com, connect by perior is useful for this special query. 3. code Java code create table TESTTEMP (parent_ID VARCHAR2 (30), son_ID VARCHAR2 (30); insert into TESTTEMP values ('1', '0 '); insert into TESTTEMP values ('1', '2'); insert into TESTTEMP values ('1', '3'); insert into TESTTEMP values ('1 ', '4'); insert into TESTTEMP values ('1', '7'); insert into TESTTEMP values ('4', '5 '); insert into TESTTEMP values ('5', '6'); insert into TESTTEMP values ('7', '8'); insert into T ESTTEMP values ('8', '9'); insert into TESTTEMP values ('9', '10'); commit; select * from TESTTEMP start with parent_ID = '1' connect by parent_ID = prior son_ID www.2cto.com result: 1 0 1 2 1 3 4 4 5 5 6 1 7 7 8 8 9 9 10 4. To sum up the above example, the function is to traverse all nodes. If prior is placed after connect by, it is searched from the top.

Related Article

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.