有路線圖(連接城市清單):查詢與週期(甲骨文10 XE和11 XE)
drop table aaa;
create table aaa(a varchar2(10), b varchar2(10));
insert into aaa values ('Rome','Berlin');
insert into aaa values ('London','Rome');
insert into aaa values ('London','New-York');
insert into aaa values ('New-York','Dallas');
我需要的路徑:柏林=>羅馬=>新紐約=>達拉斯
變型1:
select sys_connect_by_path(DECODE(a, PRIOR a, b, a),'=>') PATH1
from aaa
start with a = 'Berlin' or b = 'Berlin'
connect by nocycle Prior a = b or prior b = a
回程:=>羅馬=>倫敦
變體2:
select sys_connect_by_path(DECODE(a, PRIOR a, b, a),'=>') PATH1
from aaa
start with a = 'Berlin' or b = 'Berlin'
connect by Prior a = b or prior b = a
返回:ERROR ORA-01436 CONNECT BY循環用戶數據
任何建議,如何獲得預期的結果與分層查詢?
如果我們在下面的順序查詢給出預期的結果插入。插入到aaa值(1,0); 插入aaa值(2,1);插入到aaa值(3,2);插入到aaa值(4,3)中的 ; – VKPRO 2013-04-24 19:30:51
我想你的意思是插入到aaa值(3,2);不插入到aaa值(2,3); – Randy 2013-04-24 21:03:32
不是。所有插入查詢,訂單ov值都是正確的。 – potapuff 2013-04-25 04:38:06