码迷,mamicode.com
首页 > 数据库 > 详细

【每日积累】-oracle之connect by 002

时间:2015-01-22 01:40:02      阅读:160      评论:0      收藏:0      [点我收藏+]

标签:

1. hierarchical query 语义分析:

技术分享

2. hierarchical query 脚本测试:

---删除已存在表

drop table test;
-- Create table
create table TEST
(
  orgno  NUMBER(10) not null,
  deptno NUMBER(10),
  deptnm VARCHAR2(20)
);
---insert date
insert into test values(1,0,‘abc‘);
insert into test values(2,1,‘bcd‘);
insert into test values(3,2,‘cde‘);
insert into test values(1,3,‘def‘);
commit;

---select data
select t.orgno,t.deptno,t.deptnm from TEST t  ;

---test connect by function:下面脚本涵盖connect by 所有关键字功能测试。
select t.*, level as l, connect_by_iscycle as iscycle,sys_connect_by_path(t.orgno,‘\‘), CONNECT_BY_ROOT t.deptnm from TEST t  
where level <= 3 /*and connect_by_isleaf = 1*/
start with t.orgno = 1
connect by nocycle prior t.orgno = t.deptno
/*group by orgno,connect_by_iscycle,level;*/

---reset database
drop table test;

【每日积累】-oracle之connect by 002

标签:

原文地址:http://www.cnblogs.com/liyanantc/p/4240503.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!