Salut tout le monde..
En fait,ayant un graphe orienté je veux chercher le plus court chemin entre 2 points. J'ai trouvé un code parfait sur internet (Building a Route Planner with Oracle SQL - Finding the quickest route in a graph by Lucas Jellema http://technology.amis.nl/blog/?p=1221) testé avec Oracle 10g.
J'ai voulu l'implémenter avec Oracle 9i mais j'ai des erreurs :
Tables :
View :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12 create table points ( id number(5) , name varchar2(30) ) / create table connections ( from_id number(5) , to_id number(5) , distance number(5) ) /
Fonction :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11 create or replace view point_connections as select from_point.name from_point , to_point.name to_point , conn.distance distance from points from_point , connections conn , points to_point where conn.from_id = from_point.id and conn.to_id = to_point.id /
--> Avertissement : Fonction créée avec erreurs de compilation.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13 create or replace function evaluate_string ( p_string in varchar2 ) return number is l_result number; begin execute immediate ’select ‘||p_string||’ from dual’ into l_result; return l_result; end evaluate_string; /
Pour tester la fonction :
--> select evaluate_string('5*4')
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3 select evaluate_string('5*4') from dual /
*
ERREUR à la ligne 1 :
ORA-06575: Fonction EVALUATE_STRING est dans un état non valide
Le plus court chemin :
--> , CONNECT_BY_ROOT from_point||sys_connect_by_path(to_point,'/') route
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 select graph.* , evaluate_string(graph.route_cost) distance from ( select level number_of_transfers , sys_connect_by_path(distance,'+') route_cost , CONNECT_BY_ROOT from_point||sys_connect_by_path(to_point,'/') route from point_connections pc connect by nocycle prior to_point = from_point start with from_point = ‘A’ — starting point of the trip ) graph where regexp_like(route,’D$’) — D is the final destination order by distance /
*
ERREUR à la ligne 5 :
ORA-00923: Mot-clé FROM absent à l'emplacement prévu
![]()
Pouvez-vous m'aider???
Merci infiniment
Partager