connect by Nocycle Prior


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卻沒事


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM