日期:2014-05-16  浏览次数:20478 次

Oracle中connect by prior .... start with

?

一 connect by prior ....start with

?废话少说上测试代码.

? ? ? ??

create table test_table_c(id number primary key,description varchar(255),parent_id number);
insert into test_table_c(id,description,parent_id) values(1,'cuiyaonan2',null);
insert into test_table_c(id,description,parent_id) values(2,'cuiyaonan20',1);
insert into test_table_c(id,description,parent_id) values(3,'cuiyaonan200',2);
insert into test_table_c(id,description,parent_id) values(4,'cuiyaonan2000',3);
insert into test_table_c(id,description,parent_id) values(5,'cuiyaonan2000@',4);
insert into test_table_c(id,description,parent_id) values(6,'cuiyaonan2000@1',5);
insert into test_table_c(id,description,parent_id) values(7,'cuiyaonan2000@16',6);

?显示结果为

?



?

?

执行语句

?

select * from test_table_c connect by prior parent_id  =  id  start with id =7;

?显示结果为:

?



?

?

执行语句

?

select * from test_table_c connect by parent_id  =  prior id  start with id =1;

?显示结果

?



?

?

注释 :prior ?表示上一条记录.?prior +字段 表示上一条记录的某个字段.如?

 parent_id  =  prior id