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!

Extracting values from string using hierarchical queries

Rama KrishnaMar 20 2020 — edited Mar 20 2020

Hi all,

I am trying to extract attachment ids from each row of my table but somehow it retuning single value more than once.

For rownbr 1 there are two attachment ids but below query retuning second attachment id 3 times.

WITH Temp as (select 1 rownbr,'Source:123,attachmentId":"4678",Source:456,attachmentId":"4679",Name:32' Sdata from dual UNION ALL

                select 2 rownbr,'Source:321,attachmentId":"4680",Source:654,attachmentId":"4681",Name:33' from dual UNION ALL

                select 3 rownbr,'Source:987,attachmentId":"4682",Source:874,attachmentId":"4683",Name:34' from dual )

      select REGEXP_cOUNT(Sdata,'attachmentId'),regexp_substr(Sdata,'attachmentId[^,]*',1,level) output

  from  Temp

  CONNECT BY level<=regexp_count(Sdata,'attachmentId');

 

Expected result:

Output:

rownbr    output

1             4678

1            4679

2            4680

2            4681

3           4682

3           4683

Please help me out.

Thanks in advance.

This post has been answered by Solomon Yakobson on Mar 20 2020
Jump to Answer
Comments
Post Details
Added on Mar 20 2020
4 comments
305 views