oracle XMLType字段使用方法

刚才研究了一下XMLType字段使用方法 ,现在给大家介绍一下。  主要是新增、查询、修改XMLType字段

表结构:

 

 

建表sql:

 

-- Create table

create table T_BOOK

(

  ID          VARCHAR2(32) not null,

  SYS_ID      VARCHAR2(32),

  TYPE        VARCHAR2(200),

  LIBRARY     VARCHAR2(32),

  TITLE       VARCHAR2(200),

  CREATE_USER VARCHAR2(64),

  SUBJECT     VARCHAR2(200),

  DESCRIPTION VARCHAR2(200),

  PUBLISHER   VARCHAR2(200),

  CONTRIBUTOR VARCHAR2(200),

  CREATE_DATE DATE,

  FORMAT      VARCHAR2(200),

  INENTIFIER  VARCHAR2(200),

  SOURCE      VARCHAR2(200),

  LANGUAGE    VARCHAR2(200),

  OTHER_DESC  XMLTYPE

)

tablespace DCP

  pctfree 10

  initrans 1

  maxtrans 255

  storage

  (

    initial 64K

    minextents 1

    maxextents unlimited

  );

-- Add comments to the table 

comment on table T_BOOK

  is '数字资源结构表';

-- Add comments to the columns 

comment on column T_BOOK.LIBRARY

  is '分区键';

-- Create/Recreate primary, unique and foreign key constraints 

alter table T_BOOK

  add constraint PK_T_BOOK primary key (ID)

  using index 

  tablespace DCP

  pctfree 10

  initrans 2

  maxtrans 255

  storage

  (

    initial 64K

    minextents 1

    maxextents unlimited

  );

 

 

新增记录:

 

insert into t_book 

(id,other_desc) 

values (1 , sys.xmlType.createXML('<name><a id="1" value="some values">abc</a></name>') );

 

insert into t_book 

(id,other_desc) 

values (2 , sys.xmlType.createXML('<name><a id="1" value="some values">abc</a><b id="2" value="some2 values">abc2</b></name> ') );

 

 

查询记录:

查询一个字段中不存在的元素时,返回null值

 

得到id=1的value变量的值

select i.other_desc.extract('//name/a[@id=1]/@value ').getStringVal() as ennames, id from t_book i

 

rowid ennames id

1 some values 1

2 some values 2

 

得到a节点的值

select id,i.other_desc.getclobval(), i.other_desc.extract('//name/a/text()').getStringVal() as truename from t_book i

 添加节点

update ris_u_res.t_data_402 t
set t.other_description=insertchildxml(other_description,
'//xmlType','COPYRIGHT',xmltype('<COPYRIGHT>1</COPYRIGHT>'))
    where t.id='721577' 

 

得到b节点id属性的值

Select i.other_desc.extract('/name/b/@id').getStringVal()    As Name FROM t_book i where i.id='1'

 

修改记录:

修改一个字段中不存在的元素时,不会对数据有修改,但是1rows updated,所以需要提交事务。

 

更新id为1的记录的XMLType字段的a元素的id为1的value的值为some new value

update t_book set other_desc=updateXML(other_desc,'//name/a[@id=1]/@value ','some new value') where id=1

更新节点里面的数据

 

update T_DATA_892 t
   set t.other_description = updateXML(t.other_description,
                                       '//xmlType/SERIALNUM_905S',
                                       '<SERIALNUM_905S>12072</SERIALNUM_905S>')
                                     where t.id='1591083'

转载于:https://my.oschina.net/kt431128/blog/224713

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值