為了更好的查詢一個樹狀結構的表
CONNECT_BY_ROOT
一張表
看下面的例子
select dirindex
start with fatherindex =
connect by fatherindex = prior dirindex
DIRINDEX FATHERINDEX DIRNAME
如何統計
select CONNECT_BY_ROOT dirindex
start with fatherindex =
connect by fatherindex = prior dirindex
CONNECT_BY_ROOTDIRINDEX FATHERINDEX RPAD(
查出來的結果中
(select CONNECT_BY_ROOT dirindex as rootindex
from t_tonedirlib
start with fatherindex =
connect by fatherindex = prior dirindex) a
group by a
ROOTINDEX COUNT(
CONNECT_BY_ISLEAF
經常有DBA因為要查找樹狀表中的葉子節點而苦惱
Oracle
from t_tonedirlib
start with fatherindex =
connect by fatherindex = prior dirindex
CONNECT_BY_ISLEAF DIRINDEX FATHERINDEX RPAD(
一看結果
CONNECT_BY_ISCYCLE
我們的樹狀屬性一般都是在一條記錄中記錄一個當前節點的ID和這個節點的父ID來實現
insert into t_tonedirlib(dirindex
select dirindex
start with fatherindex =
connect by fatherindex = prior dirindex
ORA
from t_tonedirlib
start with fatherindex =
connect by NOCYCLE fatherindex = prior dirindex
CONNECT_BY_ISCYCLE DIRINDEX FATHERINDEX RPAD(
以上就是在
From:http://tw.wingwit.com/Article/program/Oracle/201311/18952.html