1.查询某节点下所有后代节点(包括各级父节点) 1 // 查询id为101的所有后代节点,包含101在内的各级父节点 2 select t.* from SYS_ORG t start with id = '101' connect by parent_id = prior id 2.查询某节点下所有后代节点(不包含各级父节点) 1 select t.* 2 from SYS_ORG t 3 where not exists (select 1 from SYS_ORG s where s.…
一.基本语法 connect by递归查询基本语法是: select 1 from 表格 start with ... connect by prior id = pId start with:表示以什么为根节点,不加限制可以写1=1,要以id为123的节点为根节点,就写为start with id =123 connect by:connect by是必须的,start with有些情况是可以省略的,或者直接start with 1=1不加限制 prior:prior关键字可以放在等号的前面,…
最近学习oracle的一些知识,发现自己sql还是很薄弱,需要继续学习,现在总结一下哈. (1)oracle递归查询 start with ... connect by prior ,至于是否向上查询(根节点)还是向下查询(叶节点),主要看prior后面跟的字段是否是父ID. 向上查询:select * from test_tree_demo start with id=1 connect by prior pid=id 查询结果: 向下查询:select * from test_tree…
直接在oracle 递归查询语句 select * from groups start with id=:DeptId connect by prior superiorid =id 往下找 select * from groups start with id=:DeptId connect by prior id=superiorid…