Comments on: Building a Route Planner with Oracle SQL – Finding the quickest route in a graph Friends of Oracle and Java Sat, 01 Aug 2015 11:10:05 +0000 hourly 1 By: Frank Zhou Wed, 12 Dec 2007 21:42:12 +0000 Here is a pure SQL solution for finding the shortest path (distance) between the source and destination



By: Lucas Jellema Sun, 22 Oct 2006 18:45:28 +0000 We got a reference to this article on the SQL Server discussion forum: I doubt however this will work in SQL Server.


By: Steffen Mazanek Mon, 21 Aug 2006 23:33:00 +0000 How does your algorithm scale?

By: Gracie Tue, 20 Jun 2006 23:31:53 +0000 Using the above code on a table with each node having distance data for all the other nodes around, the result show that the route could go back to the original node – doesn’t ” nocycle” take acre of that? Here is the a sample of the result
3 +3+3+3 StRita/JCampbl/StRita/SisTheresa 9
3 +3+5+1 StRita/JCampbl/BrockHS/SisTheresa 9
4 +3+3+5+1 StRita/JCampbl/StRita/BrockHS/SisTheresa 12
5 +3+3+6+1+1 StRita/JCampbl/StRita/JrHigh/BrockHS/SisTheresa 14

As you can see, St Rita appears twice in the route. Any suggestions would be a great help. Thanks

By: Karl Mon, 12 Jun 2006 17:52:14 +0000 I am very impressed about what via SQL can be done. Even Lucas Example is an easy one it could be an idea for using it in an application. I see always an area of practical use without the demand of Oracle Spatial.

By: salem Wed, 07 Jun 2006 16:00:54 +0000 Ever looked at the network data model that is supported by oracle Spatial Option?

By: Justin Lokitz Wed, 07 Jun 2006 06:06:51 +0000 The link in the last post for the Oracle10g Spatial Network Model should be:

By: Justin Lokitz Wed, 07 Jun 2006 06:04:31 +0000 Lucas…although I think what you’ve done here is quite impressive, Oracle10g already has this functionality (and quite a bit more) and it’s called Oracle Spatial. In fact, Orace10g Spatial has actual multimodal route planning as well as complex network (graph) analysis. Check out for more. Again, your work is pretty fantastic, but you may find that you are in fact trying to reinvent the wheel.

By: Jeroen van Wilgenburg Tue, 06 Jun 2006 12:37:49 +0000 Really interesting that this is possible with a database. But I think it’s more efficient to write a small program to solve this problem. The problem you described is called the shortest path problem
The most famous algorithm to solve this problem is developed by Dijkstra.

The graph in the article is too simple to show the benefit of the algorithm, so I created my own to explain the basics of the algorithm:

First we have to pick a random path to start with. It’s not completely random (but if you implement this with a computer it is). Let’s take ABEG (yes, I know ADG is the shortest)
The length of ABEG is 5. This is the shortest path so far. From B we can also branch to H. But 1+5>5, that path is to long, no matter what it does after point H. So we can stop here.

The algorithm also deals with cycles. Take ABEIJ for example. We can loop infinitely in the cycle EIJ, but at a certain moment it’s longer than 5 and we can stop (note that you still need some kind of cycle detection if this is the branch you started with, but a simple maximum length would do the trick because you can guess that the shortest path is not more than 20)

Let’s take the ADG now. ADG is length 3, it’s less than 5 so our new shortest path is 3. When we take the branch AC it’s 3, so we can stop immediately and conclude the shortest path is 3.

But the article still can be very useful for other problems or when you need the lengths of all routes (ie. for routing algorithms of computer networks)