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!

Hierarchy Data into Flat table structure

3410125Nov 8 2018 — edited Nov 22 2018

How to populate the hierarchy data of below table in flat format like below:

Source table data
ChildParent
MANK
KANMANK
AWIKAN
MANKAN
AMKAN
MISTIAWI
RASMANK

Target table data:

LEVEL1LEVEL2LEVEL3LEVEL4LEVEL5
MANKKANAWIMISTIMISTI
MANKKANAWIAWIAWI
MANKKANMANMANMAN
MANKKANAMAMAM
MANKMANKMANKMANKMANK
MANKKANKANKANKAN

I have use the below code but it produces null values as well:

select substr(regexp_substr(scbp, '-[^-]*', 1, 1),2) as l1,

       substr(regexp_substr(scbp, '-[^-]*', 1, 2),2) as l2,

       substr(regexp_substr(scbp, '-[^-]*', 1, 3),2) as l3,

       substr(regexp_substr(scbp, '-[^-]*', 1, 4),2) as l4,

       substr(regexp_substr(scbp, '-[^-]*', 1, 5),2) as l5,

       substr(regexp_substr(scbp, '-[^-]*', 1, 6),2) as l6

from (

select sys_connect_by_path(child, '-') scbp

from test_7nov18

start with parent is null

connect by prior child = parent

);

Comments
Post Details
Added on Nov 8 2018
9 comments
1,108 views