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