There is roadmap (list of connected cities):
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');
I need to get path: Berlin=>Rome=>New-York=>Dallas
Variant 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
Return: =>Rome=>London
Variant 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
Return: ERROR ORA-01436 CONNECT BY loop in user data
Any suggestion, how to get expected result with hierarchical query?