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!

Query to find cyclic or circular references

Sid_ Z.Aug 23 2022

Hi All,
Oracle version - 19c
I have a table with item and subitem, One item can have many subitems and also subitem can be a part of item but it can be a part of item where it was a subitem.
Data is shown below for reference:

with test as
( select 328666 item, 118331 sub_item from dual union all
 select 328666 item, 116716 sub_item from dual union all
 select 328666 item, 113453 sub_item from dual union all
 select 328666 item, 100049 sub_item from dual union all
 select 609920 item, 123491 sub_item from dual union all
 select 609920 item, 136945 sub_item from dual union all
 select 609920 item, 109049 sub_item from dual union all
 select 100049 item, 111208 sub_item from dual union all
 select 100049 item, 101350 sub_item from dual union all
 select 100049 item, 328666 sub_item from dual 
 )
 select item,sub_item from test;

O/P
Item     sub_item
100049   328666 

Actually Item 328666 have 4 sub items and out of these one of the sub item becomes a 
parent for this
This post has been answered by Frank Kulash on Aug 23 2022
Jump to Answer
Comments
Post Details
Added on Aug 23 2022
1 comment
1,434 views