Showing posts with label oracle recursive tree search. Show all posts
Showing posts with label oracle recursive tree search. Show all posts

Thursday, June 7, 2007

Oracle support for hierarchical queries

Most of us already encountered the problem of walking through a tree-like structure in database table. Imagine a PERSON table with parent-child relationship, and we want to retrieve all descendants of a person quickly. In plain JDBC and standard SQL, you'll need to write yourself a recursive function and perform multiple requests on your favorite database. Good news for users of Oracle 10g databases: Oracle SQL has extensions to fetch all descendants in one single query! You just need to use the START WITH and CONNECT BY keywords. Have a quick look at this Oracle article for more details.

Thanks to ITwise and DbMotive for the great tip!