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

PL/SQL XML解析问题:动态命名空间下无法获取标签值

解决PL/SQL中动态命名空间XML标签取值问题

可以不用硬编码命名空间前缀或URI,通过在XPath中结合local-name()匹配标签名,忽略命名空间的影响。

修改后的SQL代码如下:

select 
  test.test_customer_id,
  test.test_customer_id_2
from (
       select column_value
       from XMLTABLE(q'~//*[local-name()='ResponseData']~'
       PASSING
            (select xmltype('<S:Envelope xmlns:S=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;>
                               <S:Body>
                                  <V2 xmlns:ns27=&quot;http://testnamespace&quot;>
                                     <ResponseData>
                                        <CustomerData>
                                           <ns27:TestCustomerId>27295343</ns27:TestCustomerId>
                                           <ns27:TestCustomerId2>27295343</ns27:TestCustomerId2>
                                        </CustomerData>
                                     </ResponseData>
                                  </V2>
                               </S:Body>
                            </S:Envelope>'
                            )
              from dual))) dlcp,
       XMLTABLE('//CustomerData' PASSING dlcp.column_value COLUMNS
                test_customer_id VARCHAR2(100) PATH '*[local-name()="TestCustomerId"]',
                test_customer_id_2 VARCHAR2(100) PATH '*[local-name()="TestCustomerId2"]') test;

关键修改说明

  • 原代码中PATH 'TestCustomerId'无法匹配带命名空间的<ns27:TestCustomerId>,因为XPath默认仅匹配无命名空间的标签。
  • 改用PATH '*[local-name()="TestCustomerId"]'后,会匹配所有本地标签名为TestCustomerId的元素,不管它属于哪个命名空间,彻底避开命名空间变更的问题。

内容的提问来源于stack exchange,提问作者babicsp

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.24 03:47:09