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!

Remove '<','>' from XMLAGG function.

3198080Nov 21 2016 — edited Nov 21 2016

Hi all,

I have the following query which gives me a HTML output through the query. Please make sure to run the query in the HR schema.

SELECT '<thead>

         <tr>

             <td>Country Id</td>

             <td>Country Name</td>

             <td style="width: 40px"></td>

         </tr>

        </thead>

        <tbody>'||RTRIM(XMLAGG(XMLELEMENT(E,"TableData",',').EXTRACT('//text()')).GetClobVal(),',')||CHR(13)||'</tbody>'

FROM (SELECT '<tr>

        <td>'||A.COUNTRY_ID||'</td>

        <td>'||A.COUNTRY_NAME||'</td>

       </tr>' AS "TableData"

FROM COUNTRIES A

WHERE A.REGION_ID  = :REGION_ID)DUAL;

Pass the REGION_ID as 1,2,3, or 4.

The output of this query is as follows.

<thead>

         <tr>

             <td>Country Id</td>

             <td>Country Name</td>

             <td style="width: 40px"></td>

         </tr>

        </thead>

        <tbody>&lt;tr&gt;

        &lt;td&gt;AR&lt;/td&gt;

        &lt;td&gt;Argentina&lt;/td&gt;

       &lt;/tr&gt;,&lt;tr&gt;

        &lt;td&gt;BR&lt;/td&gt;

        &lt;td&gt;Brazil&lt;/td&gt;

       &lt;/tr&gt;,&lt;tr&gt;

        &lt;td&gt;CA&lt;/td&gt;

        &lt;td&gt;Canada&lt;/td&gt;

       &lt;/tr&gt;,&lt;tr&gt;

        &lt;td&gt;MX&lt;/td&gt;

        &lt;td&gt;Mexico&lt;/td&gt;

       &lt;/tr&gt;,&lt;tr&gt;

        &lt;td&gt;US&lt;/td&gt;

        &lt;td&gt;United States of America&lt;/td&gt;

       &lt;/tr&gt;

</tbody>

I need to remove these '&lt;' signs which should be '<', '&gt;' should be '>'. The whole query output should be in the expected format. Please let me know how to do it using the XMLAGG method as I have a big set of data to be aggregated which cannot be implemented using LISTAGG or WM_CONCAT.

Thanks.

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 19 2016
Added on Nov 21 2016
1 comment
1,735 views