I have a table called SOAP_MONITORING in which i have RESPONSE_XML column which is CLOB datatype. In this column large xml string is stored. I want to get the node name and node value from this xml string. Here is my 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>
I want to query this column in order to get the SUBSCRIPTION_ID
which is 201501070917439804
. I tried the above query
SELECT extractvalue(RESPONSE_XML, '/*/ax2130/*/id/@value')
FROM SOAP_MONITORING where WEB_SERVICE_NAME='RatorWebShopService' and WEB_METHOD_NAME='placeShopOrder'
but received an error
ORA-00932: inconsistent datatypes: expected - got -
00932. 00000 - "inconsistent datatypes: expected %s got %s"
I am very much new in order to run such queries to get the node value from xml.
Do:
In stead of:
You can convert your CLOB to an XMLType, assuming it's valid, just with:
Not sure why your column type isn't XMLType if you're storing XML in it, but that's not entirely relevant.
You could then supply the namespace to
extractvalue()
:.. but you have multiple IDs, so you get:
ORA-19025: EXTRACTVALUE returns value of only one node
.And
extractvalue
is deprecated, as noted in the documentationYou can use XQuery instead, specifically here an XMLTable.
Assuming you only want the
ax2130:id
values nested insideax2147:subscription
, you can use this XQuery:Or if you want any
ax:2130
node anywhere, including the blank one, you can use:Only the namespaces referred to in the XQuery need to be specified in the XMLNamespaces clause.
You can join to another table based on the selected IDs if you need to: