Oracle遞迴查詢

2022-01-16 13:40:37 字數 362 閱讀 2186

遞迴查詢例子:

查詢id為1的所有字部門

select id,deptcode,deptname

from department

start with id = 1

connect by prior id = parentdeptid;

start with 表示從哪一行記錄開始遞迴查詢,即根節點

connect by 表示進行遞迴,後面跟遞迴條件

prior 表示前一條記錄,表示上一條記錄的id = 下一條記錄的parentdeptid

比如上面的sql語句就可以理解為,以id 為1的記錄為根節點,遞迴查詢下一條記錄的parentdeptid = 前一條記錄的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 逆向遞迴查詢 oracle遞迴查詢

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

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

start with.connect by子句遞迴查詢一般用於乙個表維護樹形結構的應用。建立示例表 create table tbl test id number,name varchar2 100 byte pid number default 0 插入測試資料 insert into tbl t...