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');
获取完整树:
select * from t2 start with root_id = 0 connect by prior id = root_id;
获取特定子树:
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;
如果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;
如:
分享到:
相关推荐
Connect By 可以列出上下级关系 构造序列 求排列组合 逆转求出下上级的关系路径
本文章详细介绍了Oracle中connect by...start with...的用法。
oracle中 connect by prior 递归算法 Oracle中start with...connect by prior子句用法 connect by 是结构化查询中用到的
oracle中的数查询,介绍的详细,有例子。
connect by:connect by是必须的,start with有些情况是可以省略的,或者直接start with 1=1不加限制 prior:prior关键字可以放在等号的前面,也可以放在等号的后面,表示的意义是不一样的,比如 prior id = pid,...
行列转换,层级关系,oracle sys_connect_by_path的用法
Oracle_start_with_connect_by_prior_用法[文].pdf
Oracle 数据库树形结构用法总结,例如SYS_CONNECT_BY_PATH 、START WITH . . . CONNECT BY . . .等具体语法介绍
NULL 博文链接:https://yunqiang-zhang-hotmail-com.iteye.com/blog/1312354
很多场合我们都会用到...sys_connect_by_path(字段名, 2个字段之间的连接符号),这里的连接符号不要使用逗号,oracle会报错,如果一定要用,可以使用replace替换一下,方法如下 REPLACE(字段名,原字符,’,’)。这个
。。。
。。。
oracle 常用函数,connect by用法,分页方法
今天无意间,看connect by的使用,看到了sys_connect_by_path的用法,算是给我一个另类的惊喜了,sys_connect_by_path(columnname, seperator) 也可以拼出串来,不过这个函数本身不是用来给我们做这个结果集连接用...
Oracle 递归查询, start with connect by prior 用法 find_in_set 函数 concat,concat_ws,group_concat 函数 MySQL 自定义函数 手动实现 MySQL 递归查询 Oracle 递归查询 在 Oracle 中是通过 start ...
如下所示 忽略以#开头的注释部分 : cams:/u01/app/oracle/product/8.1.7:Y 其中 cams 为实例 ID /u01/app/oracle/product/8.1.7为 ORACLE_HOME目 录 Y表示允许使用 dbstart和 dbshut 启动和关闭该实例...
下面按类别列出一些ORACLE用户常用数据字典的查询使用方法。 1、用户 查看当前用户的缺省表空间 SQL>select username,default_tablespace from user_users; 查看当前用户的角色 SQL>select * from user_...
7.1 基本的GROUP BY用法 171 7.2 HAVING子句 174 7.3 GROUP BY的“新”功能 175 7.4 GROUP BY的CUBE扩展 175 7.5 CUBE的实际应用 179 7.6 通过GROUPING()函数排除空值 185 7.7 用GROUPING()来扩展报告 186 ...