I need to be able to calculate the minimum distance between two cities given a table that has the distances between pairs of cities. Two cities may not be connected directly, instead they may be connected via a third city and so on.
Here are the tables that I have
SQL> desc city
Name Null? Type
----------------------------------------- -------- ------------
CITY_ID NOT NULL NUMBER
CITY_NAME NOT NULL VARCHAR2(80)
CITY_STATE VARCHAR2(80)
ACTIVE CHAR(1)
and
SQL> desc connection
Name Null? Type
----------------------------------------- -------- -------
CITY1 NOT NULL NUMBER
CITY2 NOT NULL NUMBER
NO_OF_DAYS NOT NULL NUMBER
I don’t know how recursion and backtracking work in pl/sql.
You could try coding Dijkstra’s algorithm in PL/SQL.
Or try this SQL solution.