This is an extension to the question XPath: Select first element with a specific attribute and pertains specifically to Oracle.
Presuming we have the following data in a column called xml_data:
<bookstore>
<category>
<book location="CAN">A1</book>
<book location="FIN">A2</book>
</category>
<category>
<book location="FIN">B1</book>
<book location="US">B2</book>
</category>
<category>
<book location="US">C2</book>
<book location="FIN">C1</book>
</category>
</bookstore>
I'm trying to select the first occurrence of a book under category with attribute location="US". For the above data, that should return B2.
The suggested solution, (/bookstore/category/book[@location='US'])[1], does not work.
It returns the following error: ORA-19110: unsupported XQuery expression
Here's a SQL Fiddle demonstrating the issue.
How can I adapt the solution to work with Oracle's idea of XPaths?