Skip to content
Advertisement

Flattening a hierarchial data set in Oracle

I have a set of data as shown below

I need to flatten this data as below:

And so on.

I can have up to 30 parent child relationship

I used the connect by and sys_connect_by_path as follows

The result set is too large. There are other trees in this table and I don’t think it just looks at the specified TREE_NAME. Its giving me all sorts of combinations.

Advertisement

Answer

If you want to see tree 'MDA_GRN_KK' then that’s the “root” of your hierarchy. You specify the root using the START WITH clause. I normally put it right before the CONNECT BY:

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