使用start with ...connect by prior 实现递归查询

例如:

表结构:

family(id,name,parent)  (id,姓名,父母id)

Oracle start with递归

根据父节点找到其下子节点

select * from family start with name='大明' connect by prior id=parent;

结果: Oracle start with递归

根据子节点遍历父节点

select * from family start with name='小小红' connect by prior parent=id;

结果:Oracle start with递归


个人理解:start with是指定根节点,connect by prior 是遍历条件,id=parent  -->   根.id=子.parent

另外可在start with前面加where 条件

相关文章:

  • 2022-12-23
  • 2022-02-04
  • 2021-05-21
  • 2021-11-23
  • 2021-10-17
  • 2022-12-23
  • 2021-10-08
猜你喜欢
  • 2022-12-23
  • 2021-11-01
  • 2021-11-27
  • 2021-06-18
  • 2021-10-17
  • 2022-12-23
相关资源
相似解决方案