Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Mailing Lists -> Oracle-L -> Re: Traversing hierarchy
Re: >> I have a table with 2 columns (descendant, ancestor) in which >> I have stored thesaurus data (narrower term, broader term). >> Now, I need to retrieve the hierarchy trees using ORACLE's >> "start with...connect by...." clauses of the SELECT stmt. >> I have no problems moving down the tree for a specific >> term (i.e., collecting all BROADER TERM relationships), but I am >> unable to move up the tree (to collect NARROWER TERM relationships) >> for that same term. Do I have to use PL/SQL to accomplish this, >> or can I do it with a simple SQL stmt? >>I would appreciate any information - the ORACLE manuals are very >> vague.
...SNIP SNIP... Karen:
A tree is as how you define it. In the case you have in mind you could change the query to read
SELECT ancestor, descendant
FROM thesaurus
CONNECT BY PRIOR descendant = ancestor
START WITH ancestor = <start value>
Hope this helps!