[英]Extract data from XML Clob using SQL from Oracle Database
[英]Can't extract the data from xml values in oracle sql
我有以下2個xml值,它們相似,存儲在request_xml列中,並且是clob數據類型:
<?xml version='1.0' encoding='utf-8'?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns5:updateRechargeTicket xmlns:ns5="http://service.soap.CDRator.com" xmlns:ns2="http://core.result.service.soap.CDRator.com/xsd" xmlns="http://core.data.soap.CDRator.com/xsd" xmlns:ns4="http://data.soap.CDRator.com/xsd" xmlns:ns3="http://payment.result.service.soap.CDRator.com/xsd">
<ns5:contextUser>
<ns4:brandKey>FNC</ns4:brandKey>
</ns5:contextUser>
<ns5:rechargeTicket>
<id xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<billingGroupId>200907111603122893</billingGroupId>
<code>TIME_DIRECTDEBIT</code>
<dateCreated xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true" />
<dayOfMonth>1</dayOfMonth>
<nextRechargeDate>2015-06-01+02:00</nextRechargeDate>
<rechargeAmount>20</rechargeAmount>
</ns5:rechargeTicket>
</ns5:updateRechargeTicket>
</S:Body>
</S:Envelope>
<?xml version='1.0' encoding='utf-8'?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><ns5:addDirectDebitPayment xmlns:ns5="http://service.soap.CDRator.com" xmlns:ns2="http://core.result.service.soap.CDRator.com/xsd" xmlns="http://core.data.soap.CDRator.com/xsd" xmlns:ns4="http://data.soap.CDRator.com/xsd" xmlns:ns3="http://payment.result.service.soap.CDRator.com/xsd"><ns5:contextUser><ns4:brandKey>FNC</ns4:brandKey></ns5:contextUser><ns5:billingGroupId>201008141448491784</ns5:billingGroupId><ns5:amount>10.0</ns5:amount></ns5:addDirectDebitPayment></S:Body></S:Envelope>
我只想使用1個選擇查詢從這2個xml值中提取BillingGroupId。 是否可能或者我想使用單獨的選擇查詢來為這2個xml值選擇BillingGroupId? 我想從此xml值中提取billingGroupID
值,但不返回任何內容。 我在無法識別的選擇查詢中犯了一個小錯誤。
這是我的查詢:
SELECT xt_billingGroupId.BILLING_GROUP_ID
FROM TEMP_SOAP_MONITORING_TOPUP sm
CROSS JOIN XMLTable(XMLNAMESPACES (
'http://schemas.xmlsoap.org/soap/envelope/' AS "soapenv",
'http://service.soap.CDRator.com' as "ns",
'http://core.data.soap.CDRator.com/xsd' as "ax2130",
'http://webshop.result.service.soap.CDRator.com/xsd' as "ax2147",
'http://core.signup.data.soap.CDRator.com/xsd' as "ns3",
'http://service.soap.CDRator.com' as "ns5",
'http://core.result.service.soap.CDRator.com/xsd' as "ax232"
),
'for $i in //ns5:billingGroupId return $i'
passing XMLType(sm.REQUEST_XML)
columns "BILLING_GROUP_ID" VARCHAR2(100) path '/') xt_billingGroupId
CROSS JOIN XMLTable(XMLNAMESPACES (
'http://core.result.service.soap.CDRator.com/xsd' as "ax232"
)
也是一種
select xt_billingGroupId.* from x,
XMLTable(XMLNAMESPACES (
'http://schemas.xmlsoap.org/soap/envelope/' AS "soapenv",
'http://service.soap.CDRator.com' as "ns",
'http://core.data.soap.CDRator.com/xsd' as "ax2130",
'http://webshop.result.service.soap.CDRator.com/xsd' as "ax2147",
'http://core.signup.data.soap.CDRator.com/xsd' as "ns3",
'http://service.soap.CDRator.com' as "ns5",
'http://core.result.service.soap.CDRator.com/xsd' as "ax232"
),
'//ns5:rechargeTicket'
passing x
columns "BILLING_GROUP_ID" VARCHAR2(100) path 'ax2130:billingGroupId',
lineitem XMLType PATH '/') xt_billingGroupId ;
您嘗試訪問沒有名稱空間前綴的節點,因此要訪問默認名稱空間,但要訪問具有特定名稱空間前綴ns5
。 您可以使用local-name()
來做到這一點:
SELECT xt_billingGroupId.BILLING_GROUP_ID
FROM TEMP_SOAP_MONITORING_TOPUP sm
CROSS JOIN XMLTable(XMLNAMESPACES (
'http://schemas.xmlsoap.org/soap/envelope/' AS "S",
'http://service.soap.CDRator.com' as "ns",
'http://core.data.soap.CDRator.com/xsd' as "ax2130",
'http://webshop.result.service.soap.CDRator.com/xsd' as "ax2147",
'http://core.signup.data.soap.CDRator.com/xsd' as "ns3",
'http://service.soap.CDRator.com' as "ns5",
'http://core.result.service.soap.CDRator.com/xsd' as "ax232"
),
'//ns5:rechargeTicket/*[local-name()="billingGroupId"]'
passing XMLType(sm.REQUEST_XML)
columns "BILLING_GROUP_ID" VARCHAR2(100) path '/') xt_billingGroupId;
BILLING_GROUP_ID
--------------------------------------------------------------------------------
200907111603122893
或通過通配符命名空間:
...
'//ns5:rechargeTicket/*:billingGroupId'
passing XMLType(sm.REQUEST_XML)
columns "BILLING_GROUP_ID" VARCHAR2(100) path '/') xt_billingGroupId
如果您希望它具有靈活性,則可以只使用通配符,而無需完全引用包含節點。 然后您也不需要XMLNameSpaces定義。 使用您的兩個示例XML:
SELECT xt_billingGroupId.BILLING_GROUP_ID
FROM TEMP_SOAP_MONITORING_TOPUP sm
CROSS JOIN XMLTable('//*:billingGroupId'
passing XMLType(sm.REQUEST_XML)
columns "BILLING_GROUP_ID" VARCHAR2(100) path '/') xt_billingGroupId
BILLING_GROUP_ID
--------------------------------------------------------------------------------
200907111603122893
201008141448491784
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.