zoukankan      html  css  js  c++  java
  • Oracle9i之xmltype应用(1)

    oracle从9i开始支持一种新的数据类型—- xmltype,用于存储和管理xml数据,并提供了很多的functions,用来直接读取xml文档和管理节点。下面将介绍xmltype的一些基本使用。

    1.建立含有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(‘abc‘) );
    插入用 sys.xmlType.createXML(‘some xml doc’)

    3.直接查询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.更新xmltype里面的数据
    update abc set xmldoc=updateXML(xmldoc,’//name/a[@id=1]/@value’,’some new value’) where ……
    (注意:如果里面没有这个节点,将不能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=……)));

  • 相关阅读:
    c#发送邮件
    时间戳转换成时间js(年-月-日,例如“2017-04-22”)
    c# 如何读取web.config中的内容(ConfigurationManager)
    fiddler抓包软件的使用--请求头--ajax
    c#之双色球
    天干地支象法
    php之属性重载和方法重载
    c#之线程随机
    C#之参数线程
    c#线程创建
  • 原文地址:https://www.cnblogs.com/pekkle/p/6568788.html
Copyright © 2011-2022 走看看