例子
pid id
a b
a c
a e
b b
b b
c c
e e
e e
d d
指定pid=a
a b
a c
a e
b b
b b
c c
e e
e e
SQL語句
connect by prior id=pid
Oracle SQL的遞歸查詢
SQL> desc comm_org_subjection
Name Null? Type
ORG_SUBJECTION_ID NOT NULL VARCHAR
ORG_ID NOT NULL VARCHAR
FATHER_ORG_ID NOT NULL VARCHAR
LOCKED_IF NOT NULL VARCHAR
START_DATE NOT NULL DATE
END_DATE DATE
EDITION_NAMEPLATE NUMBER(
CODE_AFFORD_IF VARCHAR
CODE_AFFORD_ORG_ID NOT NULL VARCHAR
CODING_SHOW_ID NUMBER(
BSFLAG VARCHAR
MODIFI_DATE DATE
CREATOR_ID VARCHAR
CREATE_DATE DATE
CREATOR VARCHAR
select * from comm_org_subjection a
start with _id=
connect by prior _subjection_id=a
select org_id from comm_org_subjection a
start with _id=
connect by prior a
From:http://tw.wingwit.com/Article/program/Oracle/201311/18535.html