关于oracle中递归取数据解析
比如有以下部门表(depts)记录信息
dept_id dept_name parent_id
100 a 0
101 a1 100
102 a2 100
103 b 0
104 b1 103
105 b2 103
106 b22 105
有时候点一个部门时还想看到其所有的下属部门,这个在oracle里显示比较容易
如想找到部门b及其所有下属部门,可以这样
select dept_name from depts start with dept_id = 103 connect by prior dept_id= parent_id
执行后得到结果为
b
b1
b2
b22
select dept_name from depts start with dept_id = 105 connect by prior dept_id= parent_id
执行后结果为
b2
b22
在实际应用过程中dept_id当然是可以当作变量了
这些早有过,还是贴上来:)
dept_id dept_name parent_id
100 a 0
101 a1 100
102 a2 100
103 b 0
104 b1 103
105 b2 103
106 b22 105
有时候点一个部门时还想看到其所有的下属部门,这个在oracle里显示比较容易
如想找到部门b及其所有下属部门,可以这样
select dept_name from depts start with dept_id = 103 connect by prior dept_id= parent_id
执行后得到结果为
b
b1
b2
b22
select dept_name from depts start with dept_id = 105 connect by prior dept_id= parent_id
执行后结果为
b2
b22
在实际应用过程中dept_id当然是可以当作变量了
这些早有过,还是贴上来:)
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步