Oracle
 sql >> Database >  >> RDS >> Oracle

Come rinominare un nodo Oracle XMLTYPE

Un'opzione è utilizzare XMLTRANSFORM per rinominare un nodo. Vedi anche ad es. Rinomina i nodi con XSLT .

with
xmldata as (select xmltype('<root>
  <fields>
    <a>foo</a>
    <b>bar</b>
  </fields>
</root>') val from dual),
stylesheet as (select '<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <!-- Identity transformation -->
  <xsl:template match="node()|@*">
    <xsl:copy>
      <xsl:apply-templates select="node()|@*"/>
    </xsl:copy>
  </xsl:template>
  <!-- Identity transformation overridden for element b -->
  <xsl:template match="b">
    <xsl:element name="c">
      <xsl:apply-templates select="node()|@*"/>
    </xsl:element>
  </xsl:template>
</xsl:stylesheet>' val from dual)
select xmltransform(x.val, s.val) from xmldata x, stylesheet s;

Uscita:

XMLTRANSFORM(X.VAL,S.VAL)
--------------------------------------------------------------------------------
<root>
  <fields>
    <a>foo</a>
    <c>bar</c>
  </fields>
</root>