Select xml element value in Oracle(在 Oracle 中选择 xml 元素值)
问题描述
我正在尝试从位于 Oracle 表的 XMLTYPE 列中的 xml 元素中提取值.我试图提取的 xml 元素有一个定义了命名空间的父元素.xml 看起来像:
I am trying to extract a value from an xml element, located in an XMLTYPE column in an Oracle Table. The xml element which I am trying to extract have a parent for which a namespace is defined. The xml looks something like:
<a>
<b xmlns="urn:www.someSite.com/myModel">
<c>my value</c>
</b>
</a>
如果我想提取a"元素的内容,它的上下文被正确返回:
If I want to extract the content of the "a" element, its context is correctly returned:
SELECT Extract(myColumn, '/a') FROM myTable;
但是为了返回c"元素的内容,我没有成功找到任何可以工作的版本.以下说明不起作用:
But for returning the content of the "c" element I didn't succeed to find any version to work. The following instructions does not work:
SELECT Extract(myColumn, '/a/b/c') FROM myTable;
SELECT Extract(myColumn, '/a/b/c', 'xmlns="urn:www.someSite.com/myModel"') FROM myTable;
SELECT Extract(myColumn, '/a/b/c', 'urn:www.someSite.com/myModel') FROM myTable;
任何人都可以帮助我,在这种情况下可以使用提取语句吗?
Can anybody help me, with the extract statement that would work in this case?
推荐答案
由于a
元素没有命名空间,所以可以在函数中不使用命名空间,先提取其子元素,然后使用命名空间从 b
中提取值:
试试:
Since the a
element does not have the namespace, you can first extract its child elements without using namespaces in the function, and then extract the value from the b
with the namespace:
Try:
select extract(extract(myColumn, 'a/*'),
'b/c/text()',
'xmlns=urn:www.someSite.com/myModel')
from myTable
这篇关于在 Oracle 中选择 xml 元素值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 Oracle 中选择 xml 元素值


基础教程推荐
- Sql Server 字符串到日期的转换 2021-01-01
- 无法在 ubuntu 中启动 mysql 服务器 2021-01-01
- SQL Server:只有 GROUP BY 中的最后一个条目 2021-01-01
- 在 VB.NET 中更新 SQL Server DateTime 列 2021-01-01
- SQL Server 中单行 MERGE/upsert 的语法 2021-01-01
- ERROR 2006 (HY000): MySQL 服务器已经消失 2021-01-01
- 将数据从 MS SQL 迁移到 PostgreSQL? 2022-01-01
- 如何在 SQL Server 的嵌套过程中处理事务? 2021-01-01
- SQL Server 2016更改对象所有者 2022-01-01
- 使用pyodbc“不安全"的Python多处理和数据库访问? 2022-01-01