oracle中对于xmlType数据节点的增删改

select t.prp_xml.getclobval(),t.*,rowId from proposal_extend t where t.prp_code=100443579;




--增加节点
update proposal_extend t set t.prp_xml=APPENDCHILDXML(t.prp_xml, '/data/proposal',sys.xmlType.createXML('<xwc>111</xwc>')) where  t.prp_code=100443579;
update proposal_extend t set t.prp_xml=insertChildXML(t.prp_xml, '/data/proposal/xwc','@version','1') where  t.prp_code=100443579;


--删除节点
update proposal_extend t set t.prp_xml=deletexml(t.prp_xml, '/data/proposal/xwc/@version') where  t.prp_code=100443579;
update proposal_extend t set t.prp_xml=deletexml(t.prp_xml, '/data/proposal/xwc') where  t.prp_code=100443579;


--更新节点
update proposal_extend t set t.prp_xml = updatexml(t.prp_xml, '/data/proposal/xwc','<xwc>222</xwc>') where t.prp_code=100443579;
update proposal_extend t set t.prp_xml = updatexml(t.prp_xml, '/data/proposal/xwc/@version','4') where t.prp_code=100443579;


--查询节点是否存在
select Existsnode(t.prp_xml,'data/proposal/xwc') from proposal_extend t where t.prp_code=100443579;
--查询节点
select extractvalue(t.prp_xml,'data/proposal/xwc') as xwc from proposal_extend t where t.prp_code=100443579;
select extractvalue(t.prp_xml,'data/proposal/xwc/@version') as xwc from proposal_extend t where t.prp_code=100443579;
--查询多个节点
select t.prp_code,x.* from 
proposal_extend t,
xmltable('/data/milestones/milestone' passing t.prp_xml
            columns aaa varchar2(50) path 'aaa',
                         bbb varchar2(50) path 'bbb',
                         ccc varchar2(50) path 'ccc',
                         seq_no varchar2(50) path '@seq_no'
                         ) x where t.prp_code=100443579;


drop table xwc_test_xml_20161209;
--节点拆分到表
create table xwc_test_xml_20161209
as select t.prp_code,x.* from 
proposal_extend t,
xmltable('/data/milestones/milestone' passing t.prp_xml
            columns aaa varchar2(50) path 'aaa',
                         bbb varchar2(50) path 'bbb',
                         ccc varchar2(50) path 'ccc',
                         seq_no varchar2(50) path '@seq_no'
                         ) x where t.prp_code=100443579;


select t.* from xwc_test_xml_20161209 t;
--节点拼接
SELECT 
XMLElement("milestones",
                    XMLAgg(XMLElement("milestone", 
                                                    XMLAttributes(t.seq_no AS "seq_no"),
                                                    XMLForest(t.aaa AS "aaa",t.bbb as "bbb",t.ccc as "ccc")
                                                  )
                               )
              )
AS "RESULT"
FROM xwc_test_xml_20161209 t WHERE t.prp_code = 100443579;


--操作示例
update proposal_extend t set t.prp_xml=deletexml(t.prp_xml, '/data/milestones') where  t.prp_code=100443579;
declare
       v_xml_str xmltype;
begin
       SELECT 
        XMLElement("milestones",
                            XMLAgg(XMLElement("milestone", 
                                                            XMLAttributes(t.seq_no AS "seq_no"),
                                                            XMLForest(t.aaa AS "aaa",t.bbb as "bbb",t.ccc as "ccc")
                                                          )
                                       )
                       )
        into v_xml_str
        FROM xwc_test_xml_20161209 t WHERE t.prp_code = 100443579;
        update proposal_extend t set t.prp_xml=APPENDCHILDXML(t.prp_xml, '/data',v_xml_str) where  t.prp_code=100443579;
end;

 

oracle xml函数文档地址

https://docs.oracle.com/database/121/SQLRF/functions002.htm#SQLRF56667

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值