Oracle recursive query and deletion of parent-child relationship records
The database often processes records of parent-child relationships. In oracle, you can use a query statement to retrieve all the sub-records at a time. Example: t1 t11 t111 t1111 t12 t121 t1211 db data field: 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 start with task_id = '000000' connect by prior task_id = parent_task_id; the result is: task_id task_name t. parent_task_id 000001 t1 000002 t11 000001 000003 t111 000002 t1111 000004 000003 t12 000005 000001 t121 000006 t1211 000005 strat with specified level start condition, that is to say, the row that meets this condition can be used as the join condition between the top-level connect by prior of the hierarchy tree, that is, what kind of row is the sub-row of the upper-level row (self-join condition) select level, id, name, parentid from temptable2 connect by prior id (child-layer column) = parentid (top-level column) start with id = 1 Delete parent-child relationship record: delete from t_task where task_id in (select task_id from t_task connect by prior task_id = parentid start with task_id = '000000'); author shaozhen