Oracle's recursive operations (tree operations) infinite tree shape

Source: Internet
Author: User

Recursive operation of Oracle (tree operation) Start with org_id = ' 1 ' Connect by prior parent_id=son_id

 1. Preface    Oracle's recursive operation, in our web page directory structure will be used frequently, is said to be the interview often out of the topic, and some things on the internet is not very clear, so I tidied up a bit, the following mainly through an example to illustrate, You can run it directly from the copy code.    www.2cto.com  2.start with org_id = ' condition 1 '  prior parent_id =  son_id; The role of    this is to find out all the tree structure, the tree directory is placed in the same table, such as  1 |--2 |--3 |--4    |--5        |--6 |--7    |--8       |--9          |--10   www.2cto.com   How this structure can be found, this particular query, connect by Perior comes in handy.  3. Code  java Code  create table testtemp   (   parent_id    VARCHAR2 (+),     son_id VARCHAR2 (+)  );    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 testtemp 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 &NB sp;   www.2cto.com   Results:  1012131445561778899Ten4. Summing up the example above, the function is to implement traversing all nodes. If Prior is behind connect by, it's the search from the top

Oracle's recursive operations (tree operations) infinite tree shape

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.