【发布时间】:2015-01-29 12:25:51
【问题描述】:
我有一个名为 SOAP_MONITORING 的表,其中有 RESPONSE_XML 列,它是 CLOB 数据类型。在此列中存储大型 xml 字符串。我想从此 xml 字符串中获取节点名称和节点值。这是我的 xml:
<?xml version='1.0' encoding='utf-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><ns:placeShopOrderResponse xmlns:ns="http://service.soap.CDRator.com">
<ns:return xmlns:ax2133="http://signup.data.soap.CDRator.com/xsd" xmlns:ax2134="http://core.signup.data.soap.CDRator.com/xsd" xmlns:ax2127="http://data.soap.CDRator.com/xsd" xmlns:ax2129="http://webshop.data.soap.CDRator.com/xsd" xmlns:ax2130="http://core.data.soap.CDRator.com/xsd" xmlns:ax2140="http://core.result.service.soap.CDRator.com/xsd" xmlns:ax2139="http://result.service.soap.CDRator.com/xsd" xmlns:ax2147="http://webshop.result.service.soap.CDRator.com/xsd" xmlns:ax2148="http://mandate.result.service.soap.CDRator.com/xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ax2147:PlaceShopOrderResultDTO">
<ax2130:id xsi:nil="true" /><ax2140:description>SOAP_GLOBAL_SUCCESS</ax2140:description>
<ax2147:subscriptions xsi:type="ax2127:SubscriptionDTO"><ax2130:id>201501070917439804</ax2130:id>
<ax2130:id>201501070917439804</ax2130:id>
</ns:return></ns:placeShopOrderResponse>
</soapenv:Body>
</soapenv:Envelope>
我想查询此列以获得SUBSCRIPTION_ID,即201501070917439804。我试过上面的查询
SELECT extractvalue(RESPONSE_XML, '/*/ax2130/*/id/@value')
FROM SOAP_MONITORING where WEB_SERVICE_NAME='RatorWebShopService' and WEB_METHOD_NAME='placeShopOrder'
但收到错误
ORA-00932: inconsistent datatypes: expected - got -
00932. 00000 - "inconsistent datatypes: expected %s got %s"
为了运行这样的查询以从 xml 中获取节点值,我非常陌生。
【问题讨论】:
-
快速回答是使用
XMLType(RESPONSE_XML),但这似乎不是有效的XML:LPX-00225: end-element tag "ns:return" does not match start-element tag "ax2147:subscriptions"。好像少了一个结束标签? (另外,extractvalue()is deprecated)。 -
实际上它是一个巨大的 xml,我已经从中删除了一些部分。这样我就可以在这里展示它。你能告诉我使用 XMLType 的查询吗?当我的列数据类型是 CLOB 时它会起作用吗?
-
我觉得你应该看看here
-
我试过这种方式 SELECT XMLTYPE(RESPONSE_XML).extract('//ax2130:id/text()').getStringVal() FROM SOAP_MONITORING where WEB_SERVICE_NAME='RatorWebShopService' and WEB_METHOD_NAME=' placeShopOrder' 但是它给出了一个错误,因为 XML 配对失败,无效的令牌 '//ax2130:id/text()'。
-
当你这样做
SELECT XMLTYPE(RESPONSE_XML) FROM SOAP_MONITORING where WEB_SERVICE_NAME='RatorWebShopService' and WEB_METHOD_NAME='placeShopOrder'时,你会得到一个错误吗?
标签: sql oracle xml-parsing nsxmlelement extract-value