将xml Node插入到Oracle中具有命名空间的CLOB列中

时间:2015-06-24 11:16:24

标签: oracle oracle11g clob xmltype

我在Oracle 11g的CLOB列中有下面的xml值。

<Energy xmlns="http://euroconsumers.org/notifications/2009/01/notification">     
    <WEBSITE>WWW.VERLAAG.BE</WEBSITE>
    <CUSTOMERID>xxxxxx</CUSTOMERID>
    <Gender>M</Gender>
    <Telephone>0000000000</Telephone>
</Energy>

我想添加一个名为:Language

的新节点

看起来像这样:

<Energy xmlns="http://euroconsumers.org/notifications/2009/01/notification">     
    <WEBSITE>WWW.VERLAAG.BE</WEBSITE>
    <CUSTOMERID>xxxxxx</CUSTOMERID>
    <Gender>M</Gender>
    <Telephone>0000000000</Telephone>
    <Language></Language>
</Energy>

我在下面的句子中使用过:

update tmp_tab_noemail_test_aankoop p1
set p1.sce_msg = insertchildxml(p1.sce_msg, '/Energy', 'Language',
                 xmltype('<Language><Language/>'),
                 'xmlns="http://euroconsumers.org/notifications/2009/01/notification')
.getclobval();

还有这一个:

update tmp_tab_noemail_test_aankoop p1
set p1.sce_msg = APPENDCHILDXML(p1.sce_msg,
                 '/Energy',
                 XMLType('<Language><Language/>'),
                 'xmlns="http://euroconsumers.org/notifications/2009/01/notification')
.getclobval()

但是这些功能都有效。

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

在您的两个语句中,您都没有将初始CLOB转换为XMLType,而新节点的结束标记格式不正确 - 您有<Language/>而不是</Language>。提供开始和结束标签,或单个自动关闭标签,而不是两者的混合。您还缺少命名空间中的结束双引号。

这两种方法都有效:

update tmp_tab_noemail_test_aankoop p1
set p1.sce_msg = insertchildxml(XMLType(p1.sce_msg), '/Energy', 'Language',
  XMLType('<Language></Language>'),
  'xmlns="http://euroconsumers.org/notifications/2009/01/notification"').getclobval();

或者:

update tmp_tab_noemail_test_aankoop p1
set p1.sce_msg = APPENDCHILDXML(XMLType(p1.sce_msg), '/Energy',
  XMLType('<Language></Language>'),
  'xmlns="http://euroconsumers.org/notifications/2009/01/notification"').getclobval();

后者看起来好一点,因为新标签显示为

<Language/>

而不是

<Language xmlns=""/>

您可以使用insertchild保留命名空间,但它会在新节点中显​​式显示,即使它与顶级Energy命名空间匹配;这在功能上并不重要,但看起来有点奇怪。