我有任何类似的soapxml:
<s:Envelope
xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<TryGetCardBalanceResponse
xmlns="http://www.eubank.kz/Bis.Info.ExternalServices.Bank">
<TryGetCardBalanceResult
xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Iban i:nil="true"/>
<Money
xmlns:a="http://www.eubank.kz/Bis">
<a:Amount>198</a:Amount>
<a:Currency>KZT</a:Currency>
</Money>
<Status>Ok</Status>
</TryGetCardBalanceResult>
</TryGetCardBalanceResponse>
</s:Body>
</s:Envelope>
需要获取值金额和货币
请帮助,我该怎么办?
我尝试过:
select extractvalue(xmltype('<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body><TryGetCardBalanceResponse xmlns="http://www.eubank.kz/Bis.Info.ExternalServices.Bank"><TryGetCardBalanceResult xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><Iban i:nil="true"/><Money xmlns:a="http://www.eubank.kz/Bis"><a:Amount>198</a:Amount><a:Currency>KZT</a:Currency></Money><Status>Ok</Status></TryGetCardBalanceResult></TryGetCardBalanceResponse></s:Body></s:Envelope>'),
'/s:Envelope/s:Body/TryGetCardBalanceResponse/TryGetCardBalanceResult/Money/a:Amount',
'xmlns:s="http://www.w3.org/2003/05/soap-envelope"
xmlns="http://www.eubank.kz/Bis.Info.ExternalServices.Bank"
xmlns:i="http://www.w3.org/2001/XMLSchema-instance"
xmlns:a="http://www.eubank.kz/Bis"') xml
from dual
但是查询返回空值
答案 0 :(得分:2)
您的's'名称空间不匹配:
select extractvalue(xmltype('<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body><TryGetCardBalanceResponse xmlns="http://www.eubank.kz/Bis.Info.ExternalServices.Bank"><TryGetCardBalanceResult xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><Iban i:nil="true"/><Money xmlns:a="http://www.eubank.kz/Bis"><a:Amount>198</a:Amount><a:Currency>KZT</a:Currency></Money><Status>Ok</Status></TryGetCardBalanceResult></TryGetCardBalanceResponse></s:Body></s:Envelope>'),
'/s:Envelope/s:Body/TryGetCardBalanceResponse/TryGetCardBalanceResult/Money/a:Amount',
-- 'xmlns:s="http://www.w3.org/2003/05/soap-envelope"
'xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"
xmlns="http://www.eubank.kz/Bis.Info.ExternalServices.Bank"
xmlns:i="http://www.w3.org/2001/XMLSchema-instance"
xmlns:a="http://www.eubank.kz/Bis"') xml
from dual
/
XML
------------------------------
198
但是,不建议使用extractValue,因此您应该改用XMLQuery。并且由于需要多个值,因此使用XMLTable会更简单:
select x.*
from xmltable (
xmlnamespaces (
default 'http://www.eubank.kz/Bis.Info.ExternalServices.Bank',
'http://schemas.xmlsoap.org/soap/envelope/' AS "s",
'http://www.w3.org/2001/XMLSchema-instance' as "i",
'http://www.eubank.kz/Bis' as "a"
),
's:Envelope/s:Body/TryGetCardBalanceResponse/TryGetCardBalanceResult/Money'
passing xmltype('<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body><TryGetCardBalanceResponse xmlns="http://www.eubank.kz/Bis.Info.ExternalServices.Bank"><TryGetCardBalanceResult xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><Iban i:nil="true"/><Money xmlns:a="http://www.eubank.kz/Bis"><a:Amount>198</a:Amount><a:Currency>KZT</a:Currency></Money><Status>Ok</Status></TryGetCardBalanceResult></TryGetCardBalanceResponse></s:Body></s:Envelope>')
columns
amount number path 'a:Amount',
currency varchar2(3) path 'a:Currency'
) x;
AMOUNT CUR
---------- ---
198 KZT
如果您的XML实际上来自表,那么您将需要交叉连接:
select x.*
from your_table t
cross join xmltable (
xmlnamespaces (
default 'http://www.eubank.kz/Bis.Info.ExternalServices.Bank',
'http://schemas.xmlsoap.org/soap/envelope/' AS "s",
'http://www.w3.org/2001/XMLSchema-instance' as "i",
'http://www.eubank.kz/Bis' as "a"
),
's:Envelope/s:Body/TryGetCardBalanceResponse/TryGetCardBalanceResult/Money'
passing xmltype(t.your_column)
columns
amount number path 'a:Amount',
currency varchar2(3) path 'a:Currency'
) x;
或者如果它实际上已经存储为XMLType而不是字符串,则只需passing t.your_column
。