oracle递归指定层级,oracle递归层级查询 start with ...... connect by prior

以部门表作为解析

表结构:dept{id:'主键',name:'部门名称',parent_id:'父亲id'}

select distinct id  from dept where name=''

start with id=1 connect by prior id= parent_id

order siblings by id --排序

条件的优先级,根据start with后的条件查询第一条数据,然后根据connect by的条件,利用先决条件(start with)查询的child为起点作为下条数据的父节点递归查询所有的数据;

其中where是根据最后所有递归出的数据再进行过滤。

转自 https://blog.csdn.net/weixin_42508058/article/details/116471235

https://www.cnblogs.com/Faith-zhang/p/16179676.html

posted @   酸牛奶  阅读(150)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek “源神”启动!「GitHub 热点速览」
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· C# 集成 DeepSeek 模型实现 AI 私有化(本地部署与 API 调用教程)
· DeepSeek R1 简明指南:架构、训练、本地部署及硬件要求
· 2 本地部署DeepSeek模型构建本地知识库+联网搜索详细步骤
点击右上角即可分享
微信分享提示