How to get the first XPath element in Oracle

In my Oracle db, I have entries like this:

<ROOT> <Event> <Type>sldkfvjhkljh</Type> <ID>591252</ID> </Event> <Data> <File> <Name>1418688.pdf</Name> <URL>/591252/1418688.pdf</URL> </File> <File> <Name>1418688.xml</Name> <URL>/591252/1418688.xml</URL> </File> </Data> </ROOT> 

I need to extract the value from the first <Name> . If I try:

 Select xmltype(xml_data).extract('//Name[1]/text()').getStringVal() from MY_TABLE 

I get:

1418688.pdf1418688.xml

Why is this and how can I get only 1418688.pdf ?

Oracle Version:

Oracle Database 10g Enterprise Edition Version 10.2.0.4.0 - 64bi

+7
sql xml oracle xpath xmltype
source share
1 answer

I think both Name elements are # 1 in this document because they are the first in their nodes. Try //File[1]/Name/text()

+12
source share

All Articles