Oracle
 sql >> Base de Dados >  >> RDS >> Oracle

Gerar arquivo XML com tags XML personalizadas fora da tabela de banco de dados Oracle


você faz isso com XMLELEMENT etc.
select xmlelement("entity-engine-xml",
                  xmlagg(
                    xmlelement(
                      "myxmlfile", 
                      xmlattributes(empno as "EMPNO",
                                    ename as "ENAME",
                                    to_char(hiredate, 'yyyy-mm-dd') as "HIREDATE",
                                    sal as "SAL",
                                    deptno as "DEPTNO"
                                    )
                    )
                  )
                 ).getclobval()
  from emp;

.
how to convert xmltype to varchar2 ???

existe um getStringVal função para isso. ou seja, veja no meu exemplo acima eu usei getClobval . há um getstringval() equivalente.

EDIT:spool:
set trims on feedback off heading off long 50000 linesize 32767 pagesize 0
col c format a32767
spool c:\temp\foo.xml
select xmlelement("entity-engine-xml",
                  xmlagg(
                    xmlelement(
                      "myxmlfile", 
                      xmlattributes(empno as "EMPNO",
                                    ename as "ENAME",
                                    to_char(hiredate, 'yyyy-mm-dd') as "HIREDATE",
                                    sal as "SAL",
                                    deptno as "DEPTNO"
                                    )
                    )
                  )
                 ).transform(xmltype('<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output omit-xml-declaration="yes" indent="yes"/>
 <xsl:template match="node()|@*">
  <xsl:copy>
   <xsl:apply-templates select="node()|@*"/>
  </xsl:copy>
 </xsl:template>
</xsl:stylesheet>')) c
  from emp;
spool off