【问题标题】:Get xmltype in field in Oracle column CLOB在 Oracle 列 CLOB 的字段中获取 xmltype
【发布时间】:2014-04-01 03:51:30
【问题描述】:
我有一个包含 xml 格式的列 CLOB 类型。
我需要通过一个简单的查询来获取该字段中所有不同类型的信息:
例如。该字段包含不同的类型:
First record:
<Message type="New Address" xmlns="http://euroconsumers.org/ecommerce/2009/01/scope/messages"><Customer ...
Second record:
<Message type="Added Email" xmlns="http://euroconsumers.org/ecommerce/2009/01/scope/messages"><Customer ...
Third record:
<Message type="New Order" xmlns="http://euroconsumers.org/ecommerce/2009/01/scope/messages"><Customer ...
我想找回:
New Address
Added Email
New Order
【问题讨论】:
标签:
sql
oracle
clob
xmltype
【解决方案1】:
这适用于您的数据:
select xmlquery('/*/@type'
passing xmltype(<clob column>)
returning content)
from <your table>;
演示:
create table t42 (clob_col clob);
insert into t42 values ('<Message type="New Address" xmlns="..."><Customer type="x"></Customer></Message>');
insert into t42 values ('<Message type="Added Email" xmlns="..."><Customer></Customer></Message>');
insert into t42 values ('<Message type="New Order" xmlns="..."><Customer></Customer></Message>');
select xmlquery('/*/@type'
passing xmltype(t42.clob_col)
returning content)
from t42;
XMLQUERY('/*/@TYPE'PASSINGXMLTYPE(T42.CLOB_COL)RETURNINGCONTENT)
----------------------------------------------------------------
New Address
Added Email
New Order
或者这个:
select xmltype(<clob_column>).extract('/*/@type')
from <your table>;
演示:
select xmltype(clob_col).extract('/*/@type')
from t42;
XMLTYPE(CLOB_COL).EXTRACT('/*/@TYPE')
-------------------------------------
New Address
Added Email
New Order
Read more关于查询 XML。