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 获取第一个元素


基础教程推荐
- 从字符串 TSQL 中获取数字 2021-01-01
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
- MySQL 5.7参照时间戳生成日期列 2022-01-01
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01
- 带更新的 sqlite CTE 2022-01-01
- 带有WHERE子句的LAG()函数 2022-01-01
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01