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