开发者

Oracle XML type parsing issue

My XML File is stored in oracle column

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

When I am try开发者_如何学编程ing to execute the below query i am not getting any result

SELECT XMLTYPE(XMLDATA).EXTRACT('//productAttribute/name/text()').getStringVal() FROM TABLE

What is wrong in my query


Welcome to the world of XMLs most annoy 'feature' - namespaces. As your XML document has namespaces defined in it, you need to specify the namespace of the nodes you are selecting. Note that there are two namespaces in your XML document, so you need to use the correct one. The following works as a PLSQL block for your 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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜