Why not something like this:
select
cfg.session_xml.extract('/ns1:configurationSession/ns1:products/ns1:product[ns1:configId=5621507]/@qty',
'xmlns:ns1="http://abc.com/schema/service"').getstringval()
from vz_cfg2_sess_xml cfg
Question
I have a XMLType column in database from which I have a condition to check for a child node text and fetch the Parent node's attribute. In the XML i need the quantity (qty="3") to be fetched when i have the ConfigId(=5621507)
My SQL:
select
cfg.session_xml.extract('/ns1:configurationSession/ns1:products/ns1:product/@qty',
'xmlns:ns1="http://abc.com/schema/service"')
from vz_cfg2_sess_xml cfg
where existsNode(cfg.session_xml,'/ns1:configurationSession/ns1:products/ns1:product/[ns1:configId=5621507]')=1;
My XML:
<ns1:configurationSession sessionId="3543737" xmlns:ns1="http://abc.com/schema/service" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<ns1:products>
<ns1:product approvalCode="N" productId="ABC" qty="1">
<ns1:configId>5229719</ns1:configId>
</ns1:product>
<ns1:product approvalCode="N" productId="DEF" qty="1">
<ns1:configId>5621506</ns1:configId>
</ns1:product>
<ns1:product approvalCode="N" productId="DEF" qty="3">
<ns1:configId>5621507</ns1:configId>
</ns1:product>
</ns1:products>
</ns1:configurationSession>
La solution
Why not something like this:
select
cfg.session_xml.extract('/ns1:configurationSession/ns1:products/ns1:product[ns1:configId=5621507]/@qty',
'xmlns:ns1="http://abc.com/schema/service"').getstringval()
from vz_cfg2_sess_xml cfg