Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Recursive SQL woes

user7229529Aug 31 2009 — edited Sep 25 2009
I have a table that stores tree structures (PeopleSoft's PSTREENODE). Basically it contains tree names and nodes in the tree with their respective parent node. Here's a bare bones example:

Tree Name | Node Name | Parent Node Name
Business | Group A |
Business | Group Aa | Group A
Design | Group A |
Design | Group Aa | Group A

As you can see, the Node Names are reusable between the trees. I'm trying to recurse through this table to display the structure of each tree. Unfortunately, since the Node Names are reused between the trees, using a Connect By Prior Node Name = Parent Node Name is causing it to skip between the trees as it recurses. What I need to do as I connect to a lower recursion level is to make sure that the Tree Name has not changed so as to make sure it's still recursing the same tree. Here is the SQL that I have, and Oracle takes it as a valid SQL:

select TreeName, NodeName
from TreeTable
start with TreeName in (select distinct TreeName from TreeTable)
connect by prior TreeName = TreeName
connect by prior NodeName = ParentNodeName

However this isn't solving the problem. It's still skipping between trees. From what I can tell, even though our Oracle 10g says this is a valid SQL, it's ignoring all but the last Connect By Prior clause. Any help would be appreciated.

P.S. using Start With TreeName = 'Business' does not help as this constraint only applies at the start of the recursion, as the command name implies. Once it goes down to Level 2 and below it starts skipping between the trees.
This post has been answered by Frank Kulash on Aug 31 2009
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 23 2009
Added on Aug 31 2009
4 comments
986 views