oracle connect by 和start with

网上找了个例子 测试了一下 貌似明白了
create table t2(
root_id number,
id number,
name varchar(5),
description varchar(10)
);

insert into t2(root_id,id,name,description) values(0,1,'a','aaa');
insert into t2(root_id,id,name,description) values(1,2,'a1','aaa1');
insert into t2(root_id,id,name,description) values(1,3,'a2','aaa2');
insert into t2(root_id,id,name,description) values(0,4,'b','bbb');
insert into t2(root_id,id,name,description) values(4,5,'b1','bbb1');
insert into t2(root_id,id,name,description) values(4,6,'b2','bbb2');

1.jpg 

select * from t2 start with root_id = 0 connect by prior id = root_id
2.jpg 

select * from t2 start with id = 1 connect by prior id = root_id;
3.jpg 


select * from t2 start with id = 4 connect by prior id = root_id;
4.jpg 

select * from t2 start with root_id = 0 connect by id = root_id;

5.jpg 
select * from t2 start with id = 1 connect by id = root_id;

6.jpg 

 
posted @ 2014-07-11 23:41  沧海一滴  阅读(268)  评论(0编辑  收藏  举报