在10g中慣用的伎倆是在外部XML操作,你在做如
xmlagg(....).extract('/*')
添加.extract('/*')
但是,這並不在11g中工作。對於使用xsl變換的兼容交叉版本,請參閱Generate XML file with Customized XML tags out of oracle database table。
10.2.0.4:
SQL> create table foo (id) as select rownum from dual connect by level <= 2;
Table created.
SQL> select xmlagg(xmlelement("id", xmlelement("id2", id))).extract('/*') a from foo;
A
--------------------------------------------------------------------------------
<id>
<id2>1</id2>
</id>
<id>
<id2>2</id2>
</id>
SQL> select xmlserialize(content xmlagg(xmlelement("id", xmlelement("id2", id))).extract('/*') indent) a from foo;
select xmlserialize(content xmlagg(xmlelement("id", xmlelement("id2", id))).extract('/*') indent) a from foo
*
ERROR at line 1:
ORA-00907: missing right parenthesis
SQL> select xmlagg(xmlelement("id", xmlelement("id2", id))).transform(xmltype('<xsl:stylesheet version="1.0"
2 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
3 <xsl:output omit-xml-declaration="yes" indent="yes"/>
4 <xsl:template match="node()|@*">
5 <xsl:copy>
6 <xsl:apply-templates select="node()|@*"/>
7 </xsl:copy>
8 </xsl:template>
9 </xsl:stylesheet>')) a from foo;
A
--------------------------------------------------------------------------------
<id>
<id2>1</id2>
</id>
<id>
<id2>2</id2>
</id>
和11.2.0.2/3:
SQL> select xmlagg(xmlelement("id", xmlelement("id2", id))).extract('/*') a from foo;
A
--------------------------------------------------------------------------------
<id><id2>1</id2></id><id><id2>2</id2></id>
SQL> select xmlserialize(content xmlagg(xmlelement("id", xmlelement("id2", id))).extract('/*') indent) a from foo;
A
--------------------------------------------------------------------------------
<id>
<id2>1</id2>
</id>
<id>
<id2>2</id2>
</id>
SQL> select xmlagg(xmlelement("id", xmlelement("id2", id))).transform(xmltype('<xsl:stylesheet version="1.0"
2 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
3 <xsl:output omit-xml-declaration="yes" indent="yes"/>
4 <xsl:template match="node()|@*">
5 <xsl:copy>
6 <xsl:apply-templates select="node()|@*"/>
7 </xsl:copy>
8 </xsl:template>
9 </xsl:stylesheet>')) a from foo;
A
--------------------------------------------------------------------------------
<id>
<id2>1</id2>
</id>
<id>
<id2>2</id2>
</id>
總之
,要做到這一點的版本agnositc,你應該使用XSL。如果你只是嘗試這個特別的東西,那麼extract
縮短在10g上輸入,而xmlserialize
在11g上縮短。
什麼Oracle版本與縮進xmlserialize只有11g – DazzaL
Oracle數據庫10g企業版版本10.2.0.4.0 - 產品 – NoodleFolk