2011-07-08 141 views
2

我的XML文件存储在Oracle列的Oracle XML类型解析问题

<?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>

当我试图执行下面的查询我没有得到任何结果

SELECT XMLTYPE(XMLDATA)。 EXTRACT( '// productAttribute /名称/文本()')。getStringVal()FROM表

什么我的查询是错误的

回答

5

欢迎禾最令人讨厌的是'功能' - 命名空间。由于XML文档中定义了名称空间,因此您需要指定所选节点的名称空间。请注意,XML文档中有两个名称空间,因此您需要使用正确的名称空间。以下作品的PLSQL块为XML:

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; 
/
+0

是的,它现在的工作....如果有产品属性的多个节点,然后我才能光标输入和分析了我们的数据和更多有在产品属性节点的多个节点和我想要把数据样本代码是' Baiying_attr_03 < productAttribute> Baiying_attr_04 false kiran