SELECT r1.region_id,parent_id          FROM cnl_region r1         WHERE r1.region_id =1         START WITH r1.region_id = 1        CONNECT BY PRIOR r1.region_id = r1.parent_id

在运行上面的SQL语句时它会报ORA-01436的错误,报这个错误原因是因为产生了循环。后来查找我的数据发现,数据region_id为1的parent_id为24684,而region_id为24684的parent_id为1,这样就产生了循环后来我把数据改过来就运行正常了。

不改变数据将下面的SQL语句改为让它不产生循环

SELECT r1.region_id,parent_id          FROM cnl_region r1         WHERE r1.region_id =1         START WITH r1.region_id = 1        CONNECT BY NOCYCLE PRIOR r1.region_id = r1.parent_id

--start with ... connect by 层次查询的用法
--建表语句
create table automobiles(
part_id number(5)
constraint pk_auto_part_id primary key,
parent_id number(5)
constraint fk_auto_ppid_ references automobiles(part_id),
part_cname varchar2(30) not null,
part_ename varchar2(30) not null,
mp_cost number(9,2),
desribe varchar2(20)
);
--插入数据

insert into automobiles values( 1,1,'汽车','mobile',84321.99,'Assembly');insert into automobiles values( 2,1,'车身','bodywork',19892.99,'Manufacture');insert into automobiles values( 3,1,'发送机','engine',42128,'Purchase');insert into automobiles values( 4,1,'附件','attached',15212,'Assembly');insert into automobiles values( 5,2,'保险杠','bumper',4812.95,'Purchase');insert into automobiles values( 6,2,'底盘','chassis',12795.11,'Manufacture');insert into automobiles values( 7,2,'行李箱','Boot',812.11,'Manufacture');insert into automobiles values( 8,6,'车轮','Wheel',2062.2,'Manufacture');insert into automobiles values( 9,6,'挡泥板','Mudguard',990,'Manufacture');insert into automobiles values( 10,8,'轮胎','Tyre',300,'Purchase');insert into automobiles values( 11,3,'发送机盘','Bonnet',3212,'Manufacture');insert into automobiles values( 12,3,'活塞','Piston',1112.2,'Manufacture');insert into automobiles values( 13,3,'汽化器','Carburetter',712.29,'Manufacture');insert into automobiles values( 14,4,'变速器','Gearbox',5712.25,'Manufacture');insert into automobiles values( 15,4,'仪表板','Dashboard',538.92,'Manufacture');insert into automobiles values( 16,14,'制动器','Carburetter',712.29,'Manufacture');insert into automobiles values( 17,14,'变速杆','Gearshift',2001,'Manufacture');insert into automobiles values( 18,17,'传动轴','Shaft',1101,'Manufacture');insert into automobiles values( 19,15,'里程表','Milometer',350.28,'Purchase');/--分层sql脚本语句练习select level,part_id,parent_id,part_cname,part_ename,mp_cost,desribe from automobilesstart with part_id=1connect by prior part_id=parent_id order by level;--缩进显示select level,    lpad(' ',2*level-1)||part_cname||' '||part_ename as partNamefrom automobilesstart with part_id=1connect by prior part_id=parent_id order by level;

在执行select level语句的时候,报如下错误:ORA-01436: CONNECT BY loop in user data
解决方案:
将第一条数据中的parent_id改为null,否则loop循环找parent_id就找不到了!

【转载地址】http://blog.csdn.net/weikaifenglove/article/details/4206979

java.sql.SQLException: ORA-01436: 用户数据中的 CONNECT BY 循环相关推荐

  1. ORA-01436: 用户数据中的CONNECT BY 循环

    起始地     目的地     距离(公里) A             B             1000 A             C             1100 A           ...

  2. ORA-01436: 用户数据中的 CONNECT BY 循环

    SELECT r1.region_id,parent_id           FROM cnl_region r1          WHERE r1.region_id =1         ST ...

  3. 数据库异常---ORA-01436: 用户数据中的 CONNECT BY loop in user data 循环

    数据库 ORA-01436: 用户数据中的 CONNECT BY  loop in user data  循环 技术qq交流群:JavaDream:251572072  教程下载,在线交流:创梦IT社 ...

  4. Java笔记-解决Cause: java.sql.SQLException: 试图在只读事务中修改数据(达梦数据库)

    解决方法: @Transactional(readOnly=false) 这里要注意,可能会失效,一定要放对位置. 要包住所有sql调用的函数的上面,不要只包一部分,不然不会生效的.

  5. ORACLE各种常见java.sql.SQLException归纳

    java.sql.SQLException错误! ORA-00904:     --invalid column name 无效列名 ORA-00942: --table or view does n ...

  6. oracle错误(一) ORA-各种常见java.sql.SQLException小结

    ORA-00904: --invalid column name 无效列名ORA-00942: --table or view does not exist 表或者视图不存在ORA-01400: -- ...

  7. oracle ora-各种常见java.sql.SQLException归纳

    va.sql.SQLException错误! ORA-00904:     --invalid column name 无效列名 ORA-00942: --table or view does not ...

  8. oracle ora-各种常见java.sql.SQLException归结

    oracle ora-各种常见java.sql.SQLException归纳 java.sql.SQLException错误! ORA-00904:     --invalid column name ...

  9. java.sql.SQLException错误

    java.sql.SQLException错误! ORA-00904: –invalid column name 无效列名 ORA-00942: –table or view does not exi ...

最新文章

  1. html 颜色叠加图片,如何在背景图片上添加颜色叠加?
  2. Carplay Hub技术
  3. Android Studio failed to resolve .....
  4. C# GDI+ 绘图
  5. [转]2022 Flutter 宣布发布 Windows 正式版
  6. Python 列表list与数组array的区别
  7. css渲染(二) 文本
  8. 5万能搞定百平家装主材、家具、家电吗?
  9. 微信小程序获取上一页路由 获取从哪个页面跳转进来的
  10. 如何将php文件通过后台导入,如何将通过url传到php后台的json在后台再次转换为json格式?...
  11. 2017百度之星程序设计大赛 - 资格赛
  12. 开源免费制造业erp erp5的优点分析
  13. 短时傅里叶变换STFT(非使用fft函数)
  14. win10提高开机速度只需要5步
  15. Qt模仿360系统托盘
  16. 【python与数据分析】CH3 python序列结构补充——字符串
  17. windows网络编程 ---网络聊天室(1)
  18. ios 使用AVFoundation从视频中提取音频
  19. Java获取随机数的3种方法和总结
  20. 2020年找呀找工作。。。

热门文章

  1. Qt--简易秒表设计
  2. 章鱼搜索网启用域名32.com上线 价格百万美元?
  3. 骁龙778G Plus性能怎么样 对比骁龙778G有多大提升
  4. xp mod android下载地址,Android
  5. 招商银行专业版,交易记录下载到本地是乱码怎么办
  6. 可视化界面设计工具-物联网实训教学辅助工具-物联网实训室
  7. C语言linux下的文件操作(1)
  8. Codeforces Round #716 (Div. 2) D. Cut and Stick
  9. 共享单车第八年:谁狂飙,谁躺平?
  10. 和菜鸟一起学linux之bluetooth学习记录基础知识