在数据库父子关系的模型中,经常会需要将数据表现为树形,带层次结构的表现,就可以采用connect by prior start with来实现了。代码 1: 2: *******************************************************************************/ 3: 4: --创建测试表,增加测试数据 5: 6:createtable dapeng_test(superid varchar2(20),id varchar2(20)); 7: 8: insert into dapeng_test values('0','1'); 9: insert into dapeng_test values('0','2'); 10: 11: insert into dapeng_test values('1','11'); 12: insert into dapeng_test values('1','12'); 13: 14: insert into dapeng_test values('2','21'); 15: insert into dapeng_test values('2','22'); 16: 17: insert into dapeng_test values('11','111'); 18: insert into dapeng_test values('11','112'); 19: 20: insert into dapeng_test values('12','121'); 21: insert into dapeng_test values('12','122'); 22: 23: insert into dapeng_test values('21','211'); 24: insert into dapeng_test values('21','212'); 25: 26: insert into dapeng_test values('22','221'); 27: insert into dapeng_test values('22','222'); 28: 29:commit; 30: 31: --层次查询示例 32:selectlevel||'层',lpad(' ',level*5)||id id 33:from dapeng_test 34:startwith superid = '0'connectbyprior id=superid; 结果