2014-11-06 90 views
-1

我與XmlType將工作在Oracle 11g中,我有這樣的標籤:如何獲取xmltype標籤中的名稱空間值?

**<ProprietaryId Namespace="CMA_ID">ad017f3a9736ce9d8cbbfc89955aa033 </ProprietaryId>**

我想知道如何獲得「命名空間」的信息?

這裏是我使用的代碼:

SELECT extractvalue(value (sr),'*/ReleaseId/ProprietaryId')as ProprietaryId 
    FROM XML_TABLE X, 
     table(xmlsequence (extract(dados, '*/ContainedReleaseList/Release')))sr 

但我只可以得到標籤的信息,而不是名字空間。

回答

0

您需要使用@來指定您需要的值的屬性。

下面是一個示例查詢。

SQL> with x(y) as (
select '<?xml version="1.0" encoding="UTF-8"?> 
<service_orders count="1"> 
     <ProprietaryId Namespace="CMA_ID">ad017f3a9736ce9d8cbbfc89955aa033 </ProprietaryId> 
</service_orders>' from dual 
) 
select 
    extractvalue(xmltype(y),'service_orders/ProprietaryId/@Namespace') as ProprietaryNamespace 
from 
    x; 

PROPRIETARYNAMESPACE 
----------------------- 
CMA_ID 

但是EXTRACTVALUE已棄用。你可以爲此使用XMLTABLE。

SQL> with x(y) as (
select '<?xml version="1.0" encoding="UTF-8"?> 
<service_orders count="1"> 
     <ProprietaryId Namespace="CMA_ID">ad017f3a9736ce9d8cbbfc89955aa033 </ProprietaryId> 
</service_orders>' from dual 
) 
select 
    prop.ProprietaryNamespace 
from 
    x, 
    xmltable('service_orders/ProprietaryId' 
     passing xmltype(x.y) 
     columns ProprietaryNamespace varchar2(20) path '@Namespace' 
     ) prop; 

PROPRIETARYNAMESPACE 
-------------------- 
CMA_ID