解析存储在 Oracle 表中的 XML 字符串
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4715696/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Parse XML string stored on Oracle Table
提问by Andrea Girardi
I've a XML string like that stored on my DB:
我有一个像这样存储在我的数据库中的 XML 字符串:
<?xml version="1.0" encoding="utf-8"?>
<AddressMaintenance>
<Label Name="lblAddress11">Address Line 1</Label><TextBox Name="txtAddress11">Zuellig Korea</TextBox>
</AddressMaintenance>
do you know if there is a way to extract the value Zuelling Koreausing XMLQuery or SQL? I can't create a temporary table because it's a validate environment so I can only read that value. I know is possible using reg exp, but, if possible I try to use XML.
您知道是否可以使用 XMLQuery 或 SQL提取Zuelling Korea的值吗?我无法创建临时表,因为它是一个验证环境,所以我只能读取该值。我知道可以使用 reg exp,但是,如果可能,我会尝试使用 XML。
thanks,
Andrea
谢谢,
安德里亚
回答by Chris Cameron-Mills
If this is stored in an XMLTYPE on a table you can use the Oracle XML functions to extract it using XPath:
如果它存储在表的 XMLTYPE 中,您可以使用 Oracle XML 函数使用 XPath 提取它:
SELECT
extractvalue(xmlcol, '/*/TextBox[@Name=''txtAddress11'']') txtaddress
FROM yourtable
Adapt the XPath to suit your needs.
调整 XPath 以满足您的需要。
See ExtractValue documentationor research other Oracle XML functions.
请参阅ExtractValue 文档或研究其他 Oracle XML 函数。
I should probably note that 11g and later, extractvalue is deprecated and you should use XMLQuery
我可能应该注意到 11g 及更高版本,extractvalue 已被弃用,您应该使用XMLQuery