How to get first element by XPath in Oracle(如何在 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 获取第一个元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 Oracle 中通过 XPath 获取第一个元素
基础教程推荐
- oracle区分大小写的原因? 2021-01-01
- 什么是 orradiag_<user>文件夹? 2022-01-01
- 在 MySQL 中:如何将表名作为存储过程和/或函数参数传递? 2021-01-01
- 如何在 SQL 中将 Float 转换为 Varchar 2021-01-01
- 表 './mysql/proc' 被标记为崩溃,应该修复 2022-01-01
- MySQL 中的类型:BigInt(20) 与 Int(20) 2021-01-01
- 在多列上分布任意行 2021-01-01
- 二进制文件到 SQL 数据库 Apache Camel 2021-01-01
- mysql选择动态行值作为列名,另一列作为值 2021-01-01
- 如何根据该 XML 中的值更新 SQL 中的 XML 2021-01-01
