How do I add an attribute to xml contained within a CLOB in an Oracle database?

主宰稳场 提交于 2019-12-12 13:18:41

问题


How do I add an attribute to xml contained within a CLOB in an Oracle database? I can use the UpdateXML function to update an existing attribute but it will not add one.


回答1:


You could use a combination of deleteXml() along with either appendChildXml(), insertChildXml(), or insertXmlBefore() to remove the existing node and then re-add it back with the new attribute now included.




回答2:


with t as (
    select 
        xmltype('<a><b c="2">1</b></a>') x,
        '/a/b' node,   --node where attribute located
        '@d' att,      --attribute name
        'new' val      --new value
    from dual
)
select 
    x,
    insertchildxml(deletexml(x,node||'/'||att), node, att, val) x_new
from t



回答3:


Simple Oracle SQL to add "attrname=attrval" to all mynode elements in the clobcol column xml in every row in mytable

update mytable s set
  s.clobcol = insertchildxml(xmltype(s.clobcol)
                            ,'//mynode'
                            ,'@attrname'
                            ,'attrval'
                            ).getclobval();


来源:https://stackoverflow.com/questions/2298666/how-do-i-add-an-attribute-to-xml-contained-within-a-clob-in-an-oracle-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!