我有一个包含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
答案 0 :(得分: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。