Recursion in Oracle

Source: Internet
Author: User

Recursion in Oracle:

Table structure similar to tree structure:
Id name parentId
1 a 0
2 A-1 1
3 B 0
4 a-1-1 2
B-1 3
6 a-1-2 2
A-2 1 7
8 a-2-1 7

SELECT * FROM table name start with id = 'Connection by prior id = parentId;

Start ...... In the usage of connect by, start with is followed by the seeds of recursion.
The seeds of recursion are the places where recursion starts. connect by is followed by "prior". If the default value is: only the starting row that meets the condition can be queried, and no recursive query is performed;
The fields placed after connect by prior indicate the direction of the query.
PRIOR and start with keywords are optional
The PRIORY operator must be placed before one of the two columns of the connection relationship. For the parent-child relationship between nodes, the PRIOR operator represents the parent node on one side and the child node on the other side to determine whether the order of the tree structure is top-down or bottom-up. In addition to column names, you can also use column expressions in the join relationship. The start with clause is optional to identify the node used as the root node for searching the tree structure. If this clause is omitted, all rows that meet the query conditions are used as the root node.

For more information about Oracle, see Oracle topics page http://www.bkjia.com/topicnews.aspx? Tid = 12

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.