Oracle XML 类型解析问题

标签 oracle extract xmltype

我的XML文件存储在oracle列中

<?xml version="1.0" encoding="UTF-8"?> <BasicProductTemplateType xmlns="http://www.asia.com/app/Product_2_0" xmlns:jBos_Common_1_0="http://www.asia.com/jBos/Common_1_0"> <jBos_Common_1_0:displayName> <jBos_Common_1_0:key>label</jBos_Common_1_0:key> </jBos_Common_1_0:displayName> <jBos_Common_1_0:description>label</jBos_Common_1_0:description> <jBos_Common_1_0:extensionProperty name="invoicingCoId" value="2"/> <jBos_Common_1_0:extensionProperty name="currencyCode" value="CNY"/> <jBos_Common_1_0:extensionProperty name="taxStatus" value="false"/> <productRatePlan> <name>Default</name> <selectionType>SELECTONE</selectionType> </productRatePlan> <productAttribute> <name>Baiying_attr_00</name> <displayName> <jBos_Common_1_0:key>Label</jBos_Common_1_0:key> </displayName> <type entityName="bmiasia.app.siulib.siu.common.StringSIU"/> <description> <jBos_Common_1_0:key>Label</jBos_Common_1_0:key> </description> <required>false</required> <source>INTERNAL</source> </productAttribute> </BasicProductTemplateType>

当我尝试执行以下查询时,我没有得到任何结果

从表中选择 XMLTYPE(XMLDATA).EXTRACT('//productAttribute/name/text()').getStringVal()

我的查询出了什么问题

最佳答案

欢迎来到 XML 世界中最烦人的“功能”——命名空间。由于 XML 文档中定义了命名空间,因此您需要指定所选节点的命名空间。请注意,XML 文档中有两个命名空间,因此您需要使用正确的命名空间。以下内容可用作 XML 的 PLSQL block :

set serveroutput on;

declare
  v_xml varchar2(32767) := '<?xml version="1.0" encoding="UTF-8"?> <BasicProductTemplateType xmlns="http://www.asia.com/app/Product_2_0" xmlns:jBos_Common_1_0="http://www.asia.com/jBos/Common_1_0"> <jBos_Common_1_0:displayName> <jBos_Common_1_0:key>label</jBos_Common_1_0:key> </jBos_Common_1_0:displayName> <jBos_Common_1_0:description>label</jBos_Common_1_0:description> <jBos_Common_1_0:extensionProperty name="invoicingCoId" value="2"/> <jBos_Common_1_0:extensionProperty name="currencyCode" value="CNY"/> <jBos_Common_1_0:extensionProperty name="taxStatus" value="false"/> <productRatePlan> <name>Default</name> <selectionType>SELECTONE</selectionType> </productRatePlan> <productAttribute> <name>Baiying_attr_00</name> <displayName> <jBos_Common_1_0:key>Label</jBos_Common_1_0:key> </displayName> <type entityName="bmiasia.app.siulib.siu.common.StringSIU"/> <description> <jBos_Common_1_0:key>Label</jBos_Common_1_0:key> </description> <required>false</required> <source>INTERNAL</source> </productAttribute> </BasicProductTemplateType>';
  v_xmltype xmltype;
begin
  v_xmltype := xmltype.createxml(v_xml);
  dbms_output.put_line(v_xmltype.EXTRACT('//productAttribute/name/text()', 'xmlns="http://www.asia.com/app/Product_2_0"').getStringVal());
end;
/

关于Oracle XML 类型解析问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6622739/

相关文章:

r - 根据另一个 data.table 的行提取 data.table 的行

oracle - 如何从 Oracle XMLTYPE 中提取叶节点

sql-server - 游标有什么问题?

jquery - 我如何在 SQL 中提出这个查询?

java - Spring Data JDBC是否支持自定义类型转换器

powershell - 从文本文件中提取 URL,然后使用 Powershell 进行解析

sql - 选择具有相同名称的记录会产生重复的结果

c++ - 如何将多项式的系数和指数提取为字符串

oracle11gr2 - 将超过 4KB 的 XMLTYPE 列数据插入 Oracle 11g 数据库时出错

java - Oracle 的 XMLType 是否支持 JDBC 批量更新?