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!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Get details from xml having multiple values for same tag

I am calling an API which is sending a xml payload. Following is a sample paylaod:

<APP_RESULT>
   <STATUS>0</STATUS>
   <REC>
      <NO>111111</NO>
      <DD>ABCD1234</DD
      <DD>WXYZ4321</DD>
   </REC>
   <REC>
      <NO>222222</NO>
      <DD>ABC7777</DD>
   </REC>
</APP_RESULT>

I have inserted this data into a table called ‘gps_xml_output_stage’ in a column , xml_data. Now, I want to be able to get the data as follows:

NO | DD
**111111|ABCD1234**

**111111|WXYZ4321**

**222222|ABC7777**

OR AS:

NO | DD
**111111|ABCD1234,WXYZ4321**

**222222|ABC7777**

I wrote a query as :

with t1 as
(select xt.* from gps_xml_output_stage x,
XMLTABLE('/APP_RESULT/REC' PASSING x.xml_data 
COLUMNS 
seq for ordinality,
"NO" varchar2(20) PATH '/REC/NO') xt),
t2 as (select xt.* from gps_xml_output_stage x,
XMLTABLE('/APP_RESULT/REC/DD' PASSING x.xml_data 
COLUMNS 
seq for ordinality,
"DD" varchar2(200) PATH '.') xt)
 select * 
 from   t1 
 full outer join t2
 using  ( seq ) ;

The result is coming as

NO | DD
111111|ABCD1234

222222|WXYZ4321

|ABC7777

Can someone help me in fixing this?

This post has been answered by BluShadow on Jan 3 2025
Jump to Answer
Comments
Post Details
Added on Jan 3 2025
5 comments
99 views