Oracle SQL Developer:在没有CDATA的情况下导出到XML

时间:2012-08-03 06:23:28

标签: sql xml oracle

最近开始使用Oracle SQL Developer。我已成功运行查询并将结果导出为XML(encoding ='UTF-8')。 e.g。

<RESULTS>
    <ROW>
        <COLUMN NAME="ACCOUNTID"><![CDATA[1]]></COLUMN>
        <COLUMN NAME="ADDRLINE1"><![CDATA[XYZ company]]></COLUMN>
        <COLUMN NAME="ADDRLINE2"><![CDATA[]]></COLUMN>
        <COLUMN NAME="ADDRLINE3"><![CDATA[999 6th AVENUE]]></COLUMN>
        <COLUMN NAME="ADDRLINE4"><![CDATA[NEW YORK]]></COLUMN>
        <COLUMN NAME="ADDRLINE5"><![CDATA[NEW YORK, NY 10112]]></COLUMN>
        <COLUMN NAME="COUNTRY"><![CDATA[USA]]></COLUMN>
    </ROW>

我的问题:有没有一种方法可以在没有CDATA defs的情况下导出?即它是“简单”的数据,我想要/需要的是:

<Row>
    <X>1</X>
    <ACCOUNTID>1</ACCOUNTID>
    <ADDRLINE1>XYZ company</ADDRLINE1>
    <ADDRLINE2/>
    <ADDRLINE3>999 6th AVENUE </ADDRLINE3>
    <ADDRLINE4>NEW YORK</ADDRLINE4>
    <ADDRLINE5>NEW YORK, NY 10112</ADDRLINE5>
    <COUNTRY>USA</COUNTRY>
</Row>

查看首选项并找不到任何有用的内容。我看到一篇很老的帖子说明生成的XML是通过XSL生成的,但我找不到任何XSL。

有没有人这样做过或有任何想法?

1 个答案:

答案 0 :(得分:0)

我最接近查询的是:

(我使用了WITH子句来生成表记录)

WITH t
  AS (SELECT '1' AS x,
             '1' AS accountid,
             'XYZ company' AS addrline1,
             NULL AS addrline2,
             '999 6th AVENUE' AS addrline3,
             'NEW YORK' AS addrline4,
             'NEW YORK, NY 10112' AS addrline5,
             'USA' AS country
        FROM dual)
SELECT xmlelement("row",
          xmlelement(x,x),
          xmlelement(accountid,accountid),
          xmlelement(addrline1,addrline1),
          xmlelement(addrline2,addrline2),
          xmlelement(addrline3,addrline3),
          xmlelement(addrline4,addrline4),
          xmlelement(addrline5,addrline5),
          xmlelement(country,country)
       )
  FROM t;

生成的输出是:

<row>
  <X>1</X>
  <ACCOUNTID>1</ACCOUNTID>
  <ADDRLINE1>XYZ company</ADDRLINE1>
  <ADDRLINE2></ADDRLINE2>
  <ADDRLINE3>999 6th AVENUE</ADDRLINE3>
  <ADDRLINE4>NEW YORK</ADDRLINE4>
  <ADDRLINE5>NEW YORK, NY 10112</ADDRLINE5>
  <COUNTRY>USA</COUNTRY>
</row>

希望它有所帮助...