What's the definition of cycle in case of absence of cycle clause?From the docs:
a row forms a cycle if one of its ancestor rows has the same values for all the columns in the column alias list for query_name that are referenced in the WHERE clause of the recursive member. In the example above, both rows have the same value for A and B and only these are in the join clause. As a result you have a cycle because both rows point to themselves as well as the other row. Cycle detection avoids this problem.
was the usage of collection wrong only because I mixed it with built-in cycle detection or aren't you recommending collections at all circumstances?There are reasons for using collections, just not this!
In this case there's a much easier way to avoid revisiting the same point: check that the new ID > current ID:
with edges (id, a, b) as (
select 1, 'X', 'Y' from dual union
select 2, 'X', 'Y' from dual
), r (l, id, parent_a, parent_b, child_a, child_b) as (
select 0, id, null, null, a, b
from edges
where id = 1
union all
select r.l + 1, e.id, r.child_a, r.child_b, e.a, e.b
from r
join edges e
on (r.child_a in (e.a, e.b) or r.child_b in (e.a, e.b))
and e.id > r.id
)
select * from r;
It looks like you're solving a true graph traversal problem, in which case it's worth looking at the graph capabilities in the database to do this. These are now
included in your database license, no extra costs!
https://blogs.oracle.com/oraclespatial/graph-database-and-analytics-for-everyone