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;