Oracle遞迴查詢的基本語法

2021-06-16 07:11:14 字數 964 閱讀 8976

以下的文章主要介紹的是oracle遞迴查詢start with...connect by子句遞迴查詢一般用於乙個表維護樹形結構的實際應用。本文主要是通過sql**的方式來引出oracle遞迴查詢start with...connect by相關的實際應用。

建立示例表:

sql**

create table tbl_test  

(  id number,  

name varchar2(100 byte),  

pid number default 0  

);  

插入測試資料:

sql**

insert into tbl_test(id,name,pid) values('1','10','0');  

insert into tbl_test(id,name,pid) values('2','11','1');  

insert into tbl_test(id,name,pid) values('3','20','0');  

insert into tbl_test(id,name,pid) values('4','12','1');  

insert into tbl_test(id,name,pid) values('5','121','2');  

sql**,從root往樹末梢遞迴

select * from tbl_test  

start with id=

1connect by prior 

id= 

pid

sql**,從末梢往樹root遞迴

select * from tbl_test  

start with id=

5connect by prior 

pid= id  

oracle 遞迴查詢 Oracle遞迴查詢

1.1 建立表與插入資料 create table district id number 10 not null,parent id number 10 name varchar2 255 byte not null alter table district add constraint distr...

ORACLE的基本語法

表 create table test names varchar2 12 dates date,num int,dou double 檢視 create or replace view vi test as select from test 同義詞 create or replace synony...

oracle 逆向遞迴查詢 oracle遞迴查詢

oracle的遞迴查詢 最近在看公司的oa系統,oa系統中基本都會有節點樹,其中對於樹上的資料展示,就是用了資料庫的遞迴查詢,在這裡總結下遞迴查詢。現在存在如下的一棵樹 不會畫樹,將就一下,該樹對應下面建立的表資料。建立如下表 create table dg id number not null,主...