Skip to content
Advertisement

how to get data from different levels in a xmltable?

I’m trying to get the values of two attributes from table MVR_DTL in column VENDOR_XML. VENDOR_XML is of datatype clob and contains an xml that looks like this

I tried running

and i get this error

I also tried

but errored out with

I’m trying to get

Could someone help me figure out what I’m missing.

Advertisement

Answer

You can move the string-join down to the columns clause:

Demo with your sample data in a CTE:

If the HIJLoop node name suggests there could be multiple JRec values too then you could concatenate those too:

which makes no difference to the output with the sample XML.

db<>fiddle


Incidentally, your second attempt sort of works; it doesn’t error but doesn’t get the right result either. The address you pass is an XML fragment with just sibling nodes, and the string-join only sees one value, consisting of the text() from those (I think… something like that). If you pass the CLoop down instead and expand the second XPath then it works:

db<>fiddle

But if you were actually getting “ORA-19279: XPTY0004 – XQuery dynamic type mismatch: expected singleton sequence – got multi-item sequence” then I suspect you have data that does actually have multiple JRec nodes; in which case see my second query above.

db<>fiddle showing that issue with this approach and my first query; and it working with my second query. So you probably need to use that:

You might need to increase the returned column sizes, too.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement