select branchid from branch where parentbranchid='BRA0000000000001' order by branchid
第一句只能查詢出父節點是BRA0000000000001的所有子節點
select br.branchid
from Branch br
start with br.branchid = 'BRA0000000000001'
connect by Nocycle Prior br.branchid = br.parentbranchid
這一句能查出父節點是BRA0000000000001的所有子節點,然后它的子節點的子節點都能查出來
語法:
[ START WITH condition ]
CONNECT BY [ NOCYCLE ] condition
select abbrname,branchid,A.PARENTBRANCHID,branchtype,branchstatus,LEVEL from branch a
where a.branchstatus='BRANCHSTATUS_1'
AND a.branchtype='BRANCHTYPE_30'
start with a.branchid='BRA0000000000002'
connect by nocycle prior a.branchid = a.parentbranchid;
小結:
測試時,不指定start with會出現重復記錄,反而不指定NOCYCLE卻沒事