如何在 Oracle 中通过 XPath 获取第一个元素 [英] How to get first element by XPath in Oracle

查看:34
本文介绍了如何在 Oracle 中通过 XPath 获取第一个元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 Oracle 数据库中,我有这样的记录:

In my Oracle db I have records like this one:

<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 a value from the first <Name> tag. If I try:

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

我明白了:

1418688.pdf1418688.xml

1418688.pdf1418688.xml

为什么会这样,我怎样才能得到 1418688.pdf?

Why is that and how can I get just 1418688.pdf?

甲骨文版本:

Oracle 数据库 10g 企业版版本 10.2.0.4.0 - 64bi

Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi

推荐答案

我认为这两个 Name 元素在本文档中都是 #1,因为在它们的节点中,它们都是第一个.试试 //File[1]/Name/text()

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

这篇关于如何在 Oracle 中通过 XPath 获取第一个元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆