MyException - 我的异常网
当前位置:我的异常网» 数据库 » Oracle中connect by prior . start with

Oracle中connect by prior . start with

www.MyException.Cn  网友分享于:2013-02-20  浏览:2次
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 

表示上一条记录的id与本条记录的parent_id值是否一致.

 

 

 

文章评论

软件开发程序错误异常ExceptionCopyright © 2009-2015 MyException 版权所有