我有以下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个select查询从这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"
)
答案 0 :(得分:3)
也是一个变种
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 ;
答案 1 :(得分:2)
您正在尝试访问没有名称空间前缀的节点,因此在默认名称空间中,但在具有特定名称空间前缀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