You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Oracle 10g XMLTABLE使用命名空间触发LPX-00601无效令牌错误求助

问题:Oracle 10.2g中提取带命名空间的XML数据报错

在Oracle 10.2g环境下,从CLOB字段提取带命名空间的XML数据时,执行查询触发以下错误:

ORA-31011: XML parsing failed
ORA-19202: Error occurred in XML processing
LPX-00601: Invalid token in '/*/par:PartItemAlternateIdTypeCode'

将命名空间前缀替换为通配符后仍报错,但无命名空间的XML查询可正常执行。该查询语句在Oracle 11g及以上版本能正常运行,推测是10.2g的版本bug。

测试用代码如下:

create table efactura (efxml clob);

insert into efactura values (
'<mes:QueryPartItemRevisionResponseMessage xmlns:mes="http://xml.namespaces.test.com/im/dsp/services/managepartitem/message" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<par:PartItem xmlns:par="http://xml.namespaces.test.com/im/dsp/cdm/data/partitem">
<par:PartItemAlternateIdentifier>
<par:AlternateIdentifierSourceId>XYZ</par:AlternateIdentifierSourceId>
<par:PartItemAlternateIdTypeCode>Type Code1</par:PartItemAlternateIdTypeCode>
<par:PartItemAlternateIdVal/>
</par:PartItemAlternateIdentifier>
<par:PartItemAlternateIdentifier>
<par:AlternateIdentifierSourceId>XYZ</par:AlternateIdentifierSourceId>
<par:PartItemAlternateIdTypeCode>Type Code2</par:PartItemAlternateIdTypeCode>
<par:PartItemAlternateIdVal/>
</par:PartItemAlternateIdentifier>
<par:PartItemAlternateIdentifier>
<par:AlternateIdentifierSourceId>ABC</par:AlternateIdentifierSourceId>
<par:PartItemAlternateIdTypeCode>Type Code3</par:PartItemAlternateIdTypeCode>
<par:PartItemAlternateIdVal>00123456</par:PartItemAlternateIdVal>
</par:PartItemAlternateIdentifier>
</par:PartItem>
</mes:QueryPartItemRevisionResponseMessage>'
);
commit;

SELECT x.*
FROM efactura  t,
     XMLTable(
       XMLNamespaces(
        'http://xml.namespaces.test.com/im/dsp/services/managepartitem/message' AS "mes",
        'http://schemas.xmlsoap.org/soap/envelope/' AS "env",
        'http://xml.namespaces.test.com/im/dsp/cdm/data/partitem' AS "par"
       ),
       '/mes:QueryPartItemRevisionResponseMessage/par:PartItem/par:PartItemAlternateIdentifier' 
       PASSING xmltype(t.efxml)
       COLUMNS
         attrType VARCHAR2(25) PATH 'par:PartItemAlternateIdTypeCode',
         attrVal  VARCHAR2(10) PATH 'par:AlternateIdentifierSourceId'
     ) x
;
兼容Oracle 10.2g的解决方案

Oracle 10.2g的XMLTable功能对命名空间的处理存在局限性,可通过XMLSequence配合EXTRACTVALUE来替代实现:

SELECT
  EXTRACTVALUE(item, '/par:PartItemAlternateIdentifier/par:PartItemAlternateIdTypeCode',
               'xmlns:mes="http://xml.namespaces.test.com/im/dsp/services/managepartitem/message" xmlns:par="http://xml.namespaces.test.com/im/dsp/cdm/data/partitem"') AS attrType,
  EXTRACTVALUE(item, '/par:PartItemAlternateIdentifier/par:AlternateIdentifierSourceId',
               'xmlns:mes="http://xml.namespaces.test.com/im/dsp/services/managepartitem/message" xmlns:par="http://xml.namespaces.test.com/im/dsp/cdm/data/partitem"') AS attrVal
FROM efactura t,
     TABLE(XMLSequence(
       EXTRACT(xmltype(t.efxml), 
               '/mes:QueryPartItemRevisionResponseMessage/par:PartItem/par:PartItemAlternateIdentifier',
               'xmlns:mes="http://xml.namespaces.test.com/im/dsp/services/managepartitem/message" xmlns:par="http://xml.namespaces.test.com/im/dsp/cdm/data/partitem"')
     )) item;

说明

  • 直接在EXTRACT和EXTRACTVALUE中指定命名空间参数,避免使用XMLNamespaces语法
  • XMLSequence将XML节点集合转换为关系型数据行,再通过EXTRACTVALUE提取对应字段值

内容的提问来源于stack exchange,提问作者Radu B.

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.02 08:05:57