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. Oracle 新增表空间文件

    ALTER TABLESPACE users ADD DATAFILE 'D:/oracle/oradata/orcl/users.dbf' SIZE 500M AUTOEXTEND ON NEXT ...

  2. Error message “Assembly must be registered in isolation” when registering Plugins in Microsoft Dynamics CRM 2011 2013 解决办法

    Error message “Assembly must be registered in isolation” when registering Plugins in Microsoft Dynam ...

  3. SSDT – Error SQL70001 This statement is not recognized in this context-摘自网络

    March 28, 2013 — arcanecode One of the most common errors I get asked about when using SQL Server Da ...

  4. JQuery Dialog 禁用X按钮关闭对话框,-摘自网络

    JQuery Dialog 禁用X按钮关闭对话框,禁用ESC键关闭代码如下:$("#div1").dialog({   closeOnEscape: false,   open: ...

  5. NDK编译路径问题

    有点偷懒,在一个使用了jni工程里面稍微修改一下,编译另外一个jni工程. 代码写完后,Android.mk等文件也写好,但是ndk-build的时候提示Android NDK:Your APP_BU ...

  6. HDU5418.Victor and World(状压DP)

    #include <iostream> #include <cstring> #include <cstdio> #include <cmath> #i ...

  7. 最简单实现跨域的方法:用 Nginx 反向代理

    本文作者: 伯乐在线 - 良少 .未经作者许可,禁止转载!欢迎加入伯乐在线 专栏作者. 什么是跨域 跨域,指的是浏览器不能执行其他网站的脚本.它是由浏览器的同源策略造成的,是浏览器对javascrip ...

  8. advanced dom scripting dynamic web design techniques Part One DOM SCRIPTING IN DETAIL CHAPTER 1 DO IT RIGHT WITH BEST PRACTICES

    You’re excited; your client is excited. All is well. You’ve just launched the client’s latest websit ...

  9. hdoj 1465 不容易系列之一

    转 原文网址   http://blog.csdn.net/liwen_7/article/details/7646451 错排问题 错排问题 就是一种递推式,不过它比较著名且常用,所以要熟记! 方法 ...

  10. [一]初识Poi

    示例代码: package com.lxl.poi; import java.io.FileOutputStream; import org.apache.poi.hssf.usermodel.HSS ...