Oracle遞歸死循環怎麼辦?

drop table test1 purge;
create table test1(id number, parent_id number,name varchar2(10));
insert into test1 values(1,2,’’);
insert into test1 values(2,1,’’);
insert into test1 values(3,2,’’);
commit;

select * from test1 start with id=1 connect by PRIOR id = parent_id;
ORA-01436: 用戶數據中的 CONNECT BY 循環

查出問題數據:
SELECT *
FROM test1 u, test1 l
where u.parent_id = l.id
AND l.parent_id = u.id;
ID PARENT_ID NAME ID PARENT_ID NAME


2 1 1 2
1 2 2 1

臨時的解決方法:使用nocycle還是可以查出數據來的,只是不循環了
select * from test1 start with id=1 connect by nocycle PRIOR id = parent_id;
ID PARENT_ID NAME


1 2
2 1
3 2
永久的解決方法,把數據調整了。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章