sql realizes cascade query of ORACLE database

Using sql to implement cascade query in ORACLE database

select *                 // field to query
from table               //table with child contact ID and parent contact ID 
start with selfid=id       //Given a startid (the field name is the sub-contact ID, and the starting ID number)
connect by prior selfid=parentid        //The connection condition is that the child joint is equal to the parent joint
 
Take a chestnut and take a look---------""""""
The db data fields are as follows:
task_id task_name parent_task_id       
000001 A 0                                
000002 A_1 000001                        
000005 A_2 000001                          
check sentence:
select t.task_id ,t.task_name ,t.parent_task_id 
from t_task t 
start with task_id='000001'
connect by prior task_id = parent_task_id;
The query structure is:
task_id             task_name         parent_task_id       
000001            A                         0                                
000002            A_1                       000001                        
000005           A_2                      000001 
 
-

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326285891&siteId=291194637