Oracle Connect By用法
oracle中的select语句可以用START WITH...CONNECT BY PRIOR子句实现递归查询,connect by 是结构化查询中用到的,其基本语法是:
select ... from <TableName> where <Conditional-1> start with <Conditional-2> connect by <Conditional-3>
<Conditional-1>:过滤条件,用于对返回的所有记录进行过滤。
<Conditional-2>:查询结果重起始根结点的限定条件。
<Conditional-3>:连接条件
例如:
数据库表结构如下:
create table t2( root_id number, id number, name varchar(5), description varchar(10) ); insert into t2(root_id,id,name,description) values(0,1,'a','aaa'); insert into t2(root_id,id,name,description) values(1,2,'a1','aaa1'); insert into t2(root_id,id,name,description) values(1,3,'a2','aaa2'); insert into t2(root_id,id,name,description) values(0,4,'b','bbb'); insert into t2(root_id,id,name,description) values(4,5,'b1','bbb1'); insert into t2(root_id,id,name,description) values(4,6,'b2','bbb2');
1.获取完整树:
select * from t2; select * from t2 start with root_id = 0 connect by prior id = root_id;
2.获取特定子树:
select * from t2 start with id = 1 connect by prior id = root_id;
select * from t2 start with id = 4 connect by prior id = root_id;
3.如果connect by prior中的prior被省略,则查询将不进行深层递归。
如:
select * from t2 start with root_id = 0 connect by id = root_id;
select * from t2 start with id = 1 connect by id = root_id;
相关推荐
Oracle start with.connect by prior子句实现递归查询
oracle中 connect by prior 递归算法 Oracle中start with...connect by prior子句用法 connect by 是结构化查询中用到的
Oracle 递归查询, start with connect by prior 用法 find_in_set 函数 concat,concat_ws,group_concat 函数 MySQL 自定义函数 手动实现 MySQL 递归查询 Oracle 递归查询 在 Oracle 中是通过 start ...
主要给大家介绍了关于Oracle递归查询start with connect by prior、的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面来一起学习学习吧
Oracle使用递归查询。查询树结构的sql。在Oracle中,递归查询要用到start with ……connect by prior……
oracle菜单树查询 使用实例 使用START WITH CONNECT BY PRIOR子句实现递归查询
前言 对于数据库中的树形结构数据,如...oracle实现递归查询的话,就可以使用start with … connect by connect by递归查询基本语法是: select 1 from 表格 start with … connect by prior id = pId start with
说到Oracle中的递归查询语法,我觉得有一些数据库基础的童鞋应该都知道,做项目的时候应该也会用到,下面本文就来介绍下关于Oracle通过递归查询父子兄弟节点的相关内容,分享出来供大家参考学习,下面话不多说了,来...
oracle中的select语句可以用START WITH…CONNECT BY PRIOR子句实现递归查询,connect by 是结构化查询中用到的,其基本语法是: 代码如下:select * from tablename start with cond1 connect by cond2 where cond3;...
Oracle中的select语句可以用START WITH…CONNECT BY PRIOR子句实现递归查询,connect by 是结构化查询中用到的,其基本语法是: select * from tablename start with cond1 connect by cond2 where cond3; ...
当你用start with connect by nocycle prior 进行递归查找数据的时候那么下面两段代码的性能肯定是有明显差别的大家用的时候 请注意了代码可以不看下面 直接看我的总结 //查询某个文件夹文件夹ID=12里面的层次数以及...
connect by prior t.parentcode = t.organcode; //递归查询父节点 select t.* from g_organ t start with t.organcode = '080' connect by t.parentcode = prior t.organcode; //递归查询子节点 1.8.7 union 和 ...
criteria.add(Restrictions.sqlRestriction("MENUITEM_ID in(select a.MENUITEM_ID from Wuxin_MENUITEM a connect by prior a.MENUITEM_ID = a.PARENT_ID"+ " start with a.MENUITEM_ID = '"+parentId+"')" )); ...