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却没事

connect by Nocycle Priorconnect by Nocycle Prior

相关文章:

  • 2022-12-23
  • 2021-07-03
  • 2022-12-23
  • 2021-08-06
  • 2021-05-04
  • 2021-07-15
  • 2021-05-28
猜你喜欢
  • 2022-12-23
  • 2021-11-02
  • 2021-07-11
  • 2021-09-01
  • 2021-12-22
  • 2021-08-28
相关资源
相似解决方案