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;
如:

Oracle start with.connect by prior子句实现递归查询的更多相关文章

  1. 在oracle中通过connect by prior来实现递归查询!

    注明:该文章为引用别人的文章,链接为:http://blog.csdn.net/apicescn/article/details/1510922 ,本人记录下来只是为了方便查看 原文: connect ...

  2. 在oracle中采用connect by prior来实现递归查询

    注明:该文章为引用别人的文章,链接为:http://blog.csdn.net/apicescn/article/details/1510922 , 记录下来只是为了方便查看 原文: connect ...

  3. [z]START WITH CONNECT BY PRIOR子句实现递归查询

    [z]http://jingyan.baidu.com/article/5d368d1e182bb93f60c05784.html START WITH CONNECT BY PRIOR这个语法主要用 ...

  4. oracle start with connect by prior 递归查询

    Oracle中的select语句可以用start with...connect by prior子句实现递归查询,connect by 是结构化查询中用到的, 其基本语法是: select ... f ...

  5. Oracle start with connect by prior 用法

    Oracle start with connect by prior 用法    语法: select * from 表名 where 条件1 start with 条件2 connect by pr ...

  6. Oracle中start with...connect by (prior)子句的用法

    connect by 是结构化查询中用到的,基本语法是:select … from tablenamestart with 条件1connect by 条件2where 条件3; 例:select * ...

  7. Oracle中start with...connect by/start with…connect by prior子句的用法

    connect by 是结构化查询中用到的,其基本语法是:select … from tablenamestart with 条件1connect by 条件2where 条件3;例:select * ...

  8. 在Oracle 中使用CONNECT BY PRIOR START WITH 语句详解

    语法:connect by 是结构化查询中用到的,其基本语法如下: start with,connect by主要目的:从表中取出树状数据.可以假想成表中存成的各条数据是分别是树中的一个结点. sel ...

  9. oracle start with connect by prior 递归查询用法

    start with 子句:遍历起始条件,有个小技巧,如果要查父结点,这里可以用子结点的列,反之亦然. connect by 子句:连接条件.关键词prior,prior跟父节点列parentid放在 ...

随机推荐

  1. mysqld_multi配置MySQL多实例

    # This is an example of a my.cnf file for mysqld_multi.# Usually this file is located in home dir ~/ ...

  2. 【原】日志处理-Spark

    日志信息如下所示: 1.1.1.1 - - [21/Jul/2014:10:00:00 -0800] "GET /majihua/article/284234 HTTP/1.1"  ...

  3. makefile 中 $@ $^ %< 使用

    这篇文章介绍在LINUX下进行C语言编程所需要的基础知识.在这篇文章当中,我们将会学到以下内容: 源程序编译 Makefile的编写 程序库的链接 程序的调试 头文件和系统求助 1.源程序的编译 在L ...

  4. Spark0.8.0的安装配置

    1.profile export SCALA_HOME=/home/hadoop/scala-2.9.3SPARK_080=/home/hadoop/spark-0.8.0export SPARK_H ...

  5. HDU4349--Xiao Ming's Hope(数论)

    输入一个n(1<=n<=108),求C(n,0),C(n,1),C(n,2)...C(n,n)有多少个奇数. Lacus定理 http://blog.csdn.net/acm_cxlove ...

  6. Python队列服务 Python RQ Functions from the __main__ module cannot be processed by workers.

    在使用Python队列服务 Python RQ 时候的报错: Functions from the __main__ module cannot be processed by workers. 原因 ...

  7. IBOutlet & IBAction

    IBOutlet UILabel *label; 这个label在Interface Builder里被连接到一个UILabel.此时,这个label的retainCount为2. 所以,只要使用了I ...

  8. JAVA之装饰者模式

    装饰模式又名包装(Wrapper)模式.装饰模式以对客户端透明的方式扩展对象的功能,是继承关系的一个替代方案. 装饰模式的结构 装饰模式以对客户透明的方式动态地给一个对象附加上更多的责任.换言之,客户 ...

  9. jpcap 配置方法,问题解决,模拟sniffer程序。(附JAVA程序,jar,dll包等环境)

    博文链接 http://www.cnblogs.com/xckk/p/4609444.html 一.   Eclipse环境下安装与配置Jpcap 相关源程序.jpcap jar包,dll包,帮助文档 ...

  10. CSS3超酷移动手机滑动隐藏側边栏菜单特效

    这是一组共4种效果很炫酷的CSS3移动手机滑动隐藏側边栏菜单特效. 这四种效果各自是:默认的点击滑动側边栏菜单效果.带3D transforms的滑动側边栏效果.文字缩放和淡入淡出效果的滑动側边栏以及 ...