I have a query that extract me some the XML nodes from my clob.
select pid, name, xml from (
select d.pid, d.name
, EXTRACT(xmltype(d.data), '//ns1:myId', 'xmlns:ns1="http://acme.com/') xml
from DATA d
order by d.pid desc
)
;
But I'd like to see what the parent elements name of the extracted xmlnode actually is. I tried
, EXTRACT(xmltype(d.data), '//ns1:myId/../name()', ...) xml
and
, EXTRACT(xmltype(d.data), '//ns1:myId/name()', ...) xml
and
, EXTRACT(xmltype(d.data), '//ns1:myId/local-name()', ...) xml
but Oracle rejects all f them with "invalid token" error messages.
My Oracle Version is "11.2.0.3.0".
Extract lets you look higher up the path, but (as noted in MOS document 301709.1; which is for 9i but still seems valid, apart from the error shown):
So you can't use the
name()
,local-name()
etc. functions, on the current or parent node. There is a workaround of sorts in that document, which can be simplified slightly rom their example to:Or in a slightly different form:
Demo with both:
But
extract()
is deprecated anyway. You could do this with XMLTable:If you need something more complicated you can pull whatever you need from the node levels, as shown in this answer; but from what you've said that's overkill here.