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!

Treewalk with indirect relationships using nocycle etc.

Richard LeggeNov 24 2016 — edited Nov 28 2016

Hi All,

Im on version 12.1 SE

I'm have a table which has relationship which is hierarchical in nature. however, its a combination of a parent / child relationship as well as a peer relationship.  I want to create a graphical map / chart which shows the relationships.

Data example

ID     Link_ID

1          2

1          3

1          4

2          1

2          5

2          6

3          1

4          5

5          2

5          4

6          2

As you can see, 1 has a relationship with 2,3,4  2 has a relationship with 1, 5 and 6 etc.

Im trying to do a treewalk (or recursive SQL) such that If I start with an entity. (2 for example), it shows me as treewalk of all relationships from 2, but doesn't cycle.

Ive tried nocycle in the treewalk, and that stops the direct relationships from cycling,  but because the records are indirectly linked back to each other. i.e  1 is connected to 2, 2 is connected to 5, and 5 is connected to 1, I get 24 rows returned when I treewalk the above data.

My actual data has only very few indirect links,  I want it to somehow show the relationship if its connected indirectly, but not start cycling through again.

select

  id,

  link_id,

  level

from tab2

connect by nocycle prior link_id = id

start with id = 1

order by 3

Any ideas, would be appreciated

Regards

Richard

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 26 2016
Added on Nov 24 2016
17 comments
1,574 views