我 们的树状属性一般都是在一条记录中记录一个当前节点的ID和 这个节点的父ID来实现。但是,一旦数据中出现了循环记录,如两个节点互为 对方父节点,系统就会报ORA-01436错误。10G中, 可以通过加上NOCYCLE关键字避免报错。并且通过CONNECT_BY_ISCYCLE属 性就知道哪些节点产生了循环:

drop table t;
create table t(cid int, pid int);
truncate table t;

/*
  1--
    |--2
    |--3
      |--5
        |--1(cycle)
      |--6
    |--4
  11--
    |--6
    |--112 
*/
-- tree number 1
insert into t(cid, pid) values(1,null);
insert into t(cid, pid) values(2,1);
insert into t(cid, pid) values(3,1);
insert into t(cid, pid) values(4,1);
insert into t(cid, pid) values(5,3);
insert into t(cid, pid) values(6,3);
-- another tree number 11
insert into t(cid, pid) values(11,null);
insert into t(cid, pid) values(112,11);
insert into t(cid, pid) values(6,11); -- node 6 in both trees
-- cycle node
insert into t(cid, pid) values(1,5);

commit;

select * from t;

-- the path in row whose iscyle=1 tells the cycle path
-- here is 1_3_5(_1)
select lpad(' ', 2 * (level - 1)) || t.cid cid,
       connect_by_root t.cid root,
       connect_by_isleaf isleaf,
       connect_by_iscycle iscycle,
       substr(sys_connect_by_path(t.cid,'_'),2) path
  from t
 start with t.pid is null
connect by nocycle t.pid = prior t.cid
 order siblings by t.cid;

-- 测试结果
SQL> select * from v$version;

BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
PL/SQL Release 10.2.0.1.0 - Production
CORE        10.2.0.1.0        Production
TNS for Linux: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production

SQL>
SQL> -- the path in row whose iscyle=1 tells the cycle path
SQL> -- here is 1_3_5(_1)
SQL> select lpad(' ', 2 * (level - 1)) || t.cid cid,
  2         --connect_by_root t.cid root,
  3         --connect_by_isleaf isleaf,
  4         connect_by_iscycle iscycle,
  5         substr(sys_connect_by_path(t.cid,'_'),2) path
  6    from t
  7   start with t.pid is null
  8  connect by nocycle t.pid = prior t.cid
  9   order siblings by t.cid;

CID                  ISCYCLE        PATH
-------------------- ----------     ----------------------------------------
1                             0     1
  2                           0     1_2
  3                           0     1_3
    5                         1     1_3_5
    6                         0     1_3_6
  4                           0     1_4
11                            0     11
  6                           0     11_6
  112                         0     11_112

9 rows selected

转载于:https://www.cnblogs.com/wait4friend/archive/2011/12/08/2334575.html

Connect By在10g中得增强, nocycle关键字等相关推荐

  1. Oracle 10g中对resumable session的增强

    从9i开始,Oracle提供了一种避免因为space Error而导致事务异常的操作,那就是resumable.通常,DBA在日常工作中,往往忽略了对空间资源上的需求,比如一个大的事务所需要的temp ...

  2. Merge用法:Oracle 10g中对Merge语句的增强

    网址:  http://www.eygle.com/digest/2009/02/mergeoracle_10gmerge.html 在Oracle 10g之前,merge语句支持匹配更新和不匹配插入 ...

  3. oracle10g数据库复制,oracle -10g 中Duplicate 复制数据库

    oracle --10g 中Duplicate 复制数据库 本次实验通过duplicate命令,在本机环境中创建一个复制数据库.目标数据库为hongye.复制数据库为catdb. 环境别名设置: al ...

  4. oracle 对象不在回收站中,Oracle 10G 中的回收站

    Oracle 10G 中的"回收站"出处:互联网 回收站,从原理上来说就是一个数据字典表,放置用户Drop掉的数据库对象信息.用户进行Drop操作的对象并没有被数据库删除,仍然会占 ...

  5. oracle数据库中的回收站,Oracle 10G 中的"回收站"-数据库专栏,ORACLE

    oracle 10g 中的"回收站" by fenng http://www.dbanotes.net 在oracle 10g中,引入了一个回收站(recycle bin)的概念. ...

  6. Oracle 10g中SCN与TimeStamp的斗转星移

    来源:赛迪网    作者:Alice 在Oracle数据库10g中,提供了函数对于SCN和时间戳进行相互转换(作为对于闪回操作的一个增强),本文将通过一个示例进行具体分析: 具体示例如下: 第一步,我 ...

  7. 【增强学习】Torch中的增强学习层

    要想在Torch框架下解决计算机视觉中的增强学习问题(例如Visual Attention),可以使用Nicholas Leonard提供的dpnn包.这个包对Torch中原有nn包进行了强大的扩展, ...

  8. Java中的增强for循环的实现原理与坑

    点击上方"方志朋",选择"设为星标" 做积极的人,而不是积极废人 在JAVA中,遍历集合和数组一般有以下三种形式: for (int i = 0; i < ...

  9. SQL Server 2008中SQL增强之三:Merge(在一条语句中使用Insert,Update,Delete)

    SQL Server 2008中SQL增强之三:Merge(在一条语句中使用Insert,Update,Delete) SQL Server 2008提供了一个增强的SQL命令Merge,用法参看MS ...

最新文章

  1. 再谈MySQL JSON数据类型
  2. 线性Attention的探索:Attention必须有个Softmax吗?
  3. django-oscar页面出现Error 10002 - Security header is not valid
  4. Nginx1.0.9配置虚拟主机
  5. Sourcetail 一款代码编辑神器,让看源码如丝般顺滑
  6. 如何将Springboot项目成功部署到linux服务器上?
  7. 强烈推荐:给去美国的新生说几句(转载),超实用
  8. mysql批量查询并替换或者更新某个字段
  9. 为什么两个controller的session的id不一样_我,为什么会离婚?我为什么离婚?
  10. 计算机视觉基础——图像处理(彩色空间互转)cpp+python
  11. php的limit分页,用php数组的array_slice分页和用limit查询分页哪个效率更高?
  12. Python 图像处理实战 | 图像的灰度非线性变换之对数变换、伽马变换
  13. linux fls函数,Linux学习笔记- find 命令详解
  14. matlab简介,Matlab简介及各历史版本
  15. springboot1.5.x+ seata1.4.2(最新版本)+springcloud ( Edgware.SR5) +eureka+feign+mybatis-plus(最新)
  16. Bundle adjustment
  17. 现代大学英语精读第二版(第四册)学习笔记(原文及全文翻译)——10B - None of This Is Fair(毫无公平可言)
  18. win10如何截屏_win10使用技巧分享!
  19. 外国用户和国内用户看待浏览器的问题
  20. js实现字符串数组转换成数字数组

热门文章

  1. linux串口输出重定向到文件,DOS 下将屏幕打印输出重定向到指定文件中(或重定向到并口/串口)...
  2. python中seaborn库_GitHub - a13544835729/python-seaborn: python seaborn库基础用法
  3. 典型微型计算机的基本结构包括,第二章 微型计算机基础.doc
  4. jsp table 中多出行数据_数据分析 | 如何基于高斯曲线拟合15分钟生活圈距离衰减规律...
  5. did双重差分法_互助问答第47期:政策时点不一致DID的问题
  6. kiban可视化入门
  7. kafaka的消息存储机制
  8. scala循环 方法与函数
  9. JAVA发送HttpClient请求及接收请求结果过程
  10. ​ [RHEL7.1]重新封装系统(制作模板)