Home > sql, xml > old-fashion listagg

old-fashion listagg

December 11th, 2008 Leave a comment Go to comments

Yesterday I had my first session about XML, today I have one about SQL Model

Ok, it was the first time I spoke about XML so I did not really now where to focus. XML is so big, you have XQUERY, XPATH, dozens of XML functions in the database.

One of the XML function is called XMLTRANSFORM and transforms XML according to XSLT

I had a fun demo about XSLT to create a semi-column separated list :


select
   deptno,
   xmltransform
   (
      sys_xmlagg
      (
         sys_xmlgen(ename)
      ),
     xmltype
     (
       '<?xml version="1.0"?><xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
          <xsl:template match="/">
            <xsl:for-each select="/ROWSET/ENAME">
              <xsl:value-of select="text()"/>;</xsl:for-each>
          </xsl:template>
        </xsl:stylesheet>'
     )
  ).getstringval() listagg
from emp
group by deptno;


 DEPTNO LISTAGG
------- --------------------------------------
     10 CLARK;KING;MILLER;
     20 SMITH;FORD;ADAMS;SCOTT;JONES;
     30 ALLEN;BLAKE;MARTIN;TURNER;JAMES;WARD;

Tags:
  1. DJ
    December 26th, 2008 at 01:03 | #1

    Wonderful! See, we SQL dinosaurs can code XML as well as the JAVA hippies.

  2. December 26th, 2008 at 07:45 | #2

    :mrgreen:

  3. Leonard
    April 28th, 2010 at 15:08 | #3

    Have used your LISTAGG workaround :-)
    Thanks!

  1. No trackbacks yet.
*