2013-01-23 66 views
0

的XML生成XML時插入新行。鑑於我有一張非常大的表,它在假脫機時達到了行長限制。如何使用</p> <pre><code>XMLAgg(XMLElement('student', ...)...) </code></pre> <p>吐出來的一切到一個行生成從SQLPLUS

我想讓每個<學生> ... ... </student>節點在單獨的行上。 This頁面建議使用XMLText(x'0A')插入新行,但SQLPlus似乎無法識別它。

我已經嘗試過:

set long 2000000000 
set linesize 32767 
set wrap on 
set trimspool on 
+1

什麼Oracle版本與縮進xmlserialize只有11g – DazzaL

+0

Oracle數據庫10g企業版版本10.2.0.4.0 - 產品 – NoodleFolk

回答

3

在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上縮短。

+0

10g部分adhoc解決方案很好,謝謝。我沒有11g環境,所以無法驗證該部分。 – NoodleFolk

相關問題