Oracle recursive query can process parent-child relationship records. The following describes how to use oracle recursive query to process parent-child relationship records for your reference.
The database often processes records of parent-child relationships. In oracle, you can use oracle recursive query statements to retrieve all the sub-records at a time. For example:
T1
T11
T111
T1111
T12
T121
T1211
The db data fields are as follows:
Task_id task_name t. parent_task_id ***
************
000001 t1 ******
000002 t11 000001 ***
000005 t12 000001 ***
000003 t111 000002 ***
000004 t1111 000003 ***
000006 t121 000005 ***
000007 t1211 000006 ***
************
Query statement:
Select t. task_id, t. task_name, t. parent_task_id
From t_task t s
Tart with task_id = '000000'
Connect by prior task_id = parent_task_id;
Result:
Task_id task_name t. parent_task_id
000001 t1
000002 t11 000001
000003 t111 000002
000004 t1111 000003
000005 t12 000001
000006 t121 000005
000007 t1211 000006
Strat with specifies the conditions for starting a hierarchy, that is, the rows that meet this condition can be used as the top layer of the hierarchy tree.
Connect by prior refers to the association condition between layers, that is, what kind of row is the upper-layer row's sub-row self-join condition)
Select level, id, name, parentid from temptable2
Connect by prior parentid (top-level column) = id (child-layer column) start with id = 1
Common ORACLE Data Types
How to query Oracle log files
Oracle index Optimization Design
Implementation of parallel query of one column in oracle
Use of oracle rownum statements