Skip to content
Advertisement

Oracle hierarchical queries data

The link gives a good example for overview on how to use Oracle hierarchical queries. I was trying to generate the below combination of data with the example table tab1 given in the link but struck for a while.Using Oracle version 12.2

Output of the above select statement

Diagraph: enter image description here

Advertisement

Answer

The sql query to get the desired output are below:

Solution 1: using CTE

Solution 2: Using Oracle only connect by query. The CONNECT BY NOCYCLE clause can be used to not traverse cyclical hierarchies if any.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement