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!

dynamic tags in XMLquery

user8048037Mar 24 2016 — edited Mar 24 2016

This query works fine:

WITH x(xd) AS

(SELECT 'Aa,Bx,D,Z' FROM dual)

SELECT XMLType('<rows>'||

         XMLQuery('for $k at $l in ora:tokenize($str,",")

                   return  <a>{$k}</a>'

           PASSING xd as "str" 

           RETURNING CONTENT)||

          '</rows>') xd

  FROM x;

XD                                                                       

---------

<rows>                                                                   

  <a>Aa</a>                                                              

  <a>Bx</a>                                                              

  <a>D</a>                                                               

  <a>Z</a>                                                               

</rows> 

I'm trying to make the tags dynamic <a1></a1>, <a2></a2>, but this isn't so easy:

WITH x(xd) AS

(SELECT 'Aa,Bx,D,Z' FROM dual)

SELECT XMLType('<rows>'||

         XMLQuery('for $k at $l in ora:tokenize($str,",")

                   return  <a{$l}>{$k}</a{$l}>'

           PASSING xd as "str" 

           RETURNING CONTENT)||

          '</rows>') xd

This post has been answered by Paulzip on Mar 24 2016
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 21 2016
Added on Mar 24 2016
7 comments
586 views