Oracle XMLType简介

1.建立含有Oracle xmltype数据类型的表create table abc (id number,xmldoc sys.xmltype);声明xmltype型字段用:sys.xmltype。

2.向带有xmltype类型的表插入带有数据insert into abc (id,xmldoc) value (abc.nextval , sys.xmlType.createXML(''<name><a id="1" value="some values">abc</a></name>'') );插入用 sys.xmlType.createXML(''some xml doc'')

3.直接查询Oracle xmltype字段里面的内容得到id=1的value变脸的值select i.xmldoc.extract(''//name/a[@id=1]/@value'').getStringVal() as ennames, id from abc i得到a节点的值select id, i.xmldoc.extract(''//name/a/text()'').getStringVal() as truename from abc i得到节点id属性的值Select hd.Data_t.extract(''/root/name/@id'').getStringVal()    As Name FROM sehr_house_data hd

4.更新Oracle xmltype里面的数据update abc set xmldoc=updateXML(xmldoc,''//name/a[@id=1]/@value'',''some new value'') where ......(注意:如果里面没有<a id="1">这个节点,将不能update)

5.添加超过4k字节的xml文档到xmltype型字段可以通过使用临时表的办法实现:
◆先建立一个临时的表,其中的一个字段是clob类型;
◆再将要写入xmltype字段的xml doc写入这个临时的clob型的字段中;
◆最后insert into abc (id,xmldoc) values (abc_q.nextval , sys.xmlType.createXML((select content from 临时表 where id=......)));

猜你喜欢

转载自www.linuxidc.com/Linux/2017-03/141677.htm