oracle 遞迴查詢 樹查詢

2021-06-02 02:36:24 字數 386 閱讀 8204

通過根節點遍歷子節點.

select level,a.deptproperty,a.*   from sys_org a 

start with a.parentid='0'

connect by prior a.org_objid=a.parentid

--通過子節點獲取頂節點

select first_value(org_objid) over

(order by level desc rows unbounded preceding)

as firstdeptid from sys_org start with org_objid='3617460111308021' connect by prior parentid=org_objid

oracle樹遞迴查詢

通過子節點向根節點追朔.deptid paredeptid name number number char 40 byte 部門id 父部門id 所屬部門id 部門名稱 sql 通過子節點遍歷根節點.select frompersons.deptstartwithdeptid 76connect b...

oracle遞迴查詢 簡單樹查詢

記錄下學習到。從deptid為100的開始往下查詢 即迴圈查詢所有parentid是該記錄deptid的所有記錄 select from dept where start with deptid 100 connect by prior deptid parentid order by deptid...

Oracle遞迴查詢 樹型查詢

prior放的左右位置決定了檢索是自底向上還是自頂向下.左邊是自上而下 找子節點 右邊是自下而上 找父節點 select t.area code,t.area name,t.area level from tbl sys area code t connect by prior t.area cod...