1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| With MaTable (Trajet, Depart, Arrivee) as
(
select 1, 'A', 'B' from dual union all
select 2, 'C', 'D' from dual union all
select 3, 'D', 'E' from dual union all
select 4, 'E', 'F' from dual union all
select 5, 'A', 'D' from dual
)
select t1.Trajet, t1.Depart, t1.Arrivee
, connect_by_root t1.Trajet as Voyage
from MaTable t1
START WITH not exists (select null
from MaTable t2
where t2.Arrivee = t1.Depart
and t2.trajet + 1 = t1.trajet)
CONNECT by PRIOR t1.Arrivee = t1.Depart
and PRIOR t1.trajet + 1 = t1.trajet
order by Voyage, Trajet;
TRAJET DEPART ARRIVEE VOYAGE
------ ------ ------- ------
1 A B 1
2 C D 2
3 D E 2
4 E F 2
5 A D 5 |
Partager