【每日积累】-oracle之connect by 002
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;
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。