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

Oracle使用XMLTABLE解析XML返回空值问题求解

问题排查结果

错误原因

  • 命名空间声明错误:你给http://www.rigidcloud.com/声明别名时多写了末尾空格,写成"c ",导致别名识别失败;同时xsi、xsd是XML Schema定义专用的命名空间,你的实际业务元素根本不在这两个命名空间下,不需要在XPath里引用这两个前缀。
  • XPath路径语法&逻辑错误:你写的/a:/b:CommunityResult /c:Information存在语法问题(a:后无对应节点名)、节点归属错误(CommunityResult不属于xsd命名空间)、多余空格,完全匹配不到XML结构。
  • 列路径匹配错误:你的XML中没有名为Durum的节点,你定义列时写的path 'Durum'不可能匹配到内容。
  • 默认命名空间配置错误:你设置了default '',但你的XML所有业务节点都在http://www.rigidcloud.com/的默认命名空间下,空默认值会导致节点匹配失败。
修正方案

如果要提取节点的内容,修正后的SQL如下:

select 
    (select x.DURUM 
     from table1, 
          xmltable(
              xmlnamespaces ('http://www.rigidcloud.com/' as "c"), 
              '/c:CommunityResult/c:Information'
              passing XMLType(column1) 
              columns "DURUM" VARCHAR2(1000) path '.'
          ) x 
     where record_code = '11102006')               
from dual;

如果要提取节点的内容,把XPath改成/c:CommunityResult/c:Situation即可。
也可以直接把业务命名空间设为默认,简化写法:

select 
    (select x.DURUM 
     from table1, 
          xmltable(
              xmlnamespaces (default 'http://www.rigidcloud.com/'), 
              '/CommunityResult/Information'
              passing XMLType(column1) 
              columns "DURUM" VARCHAR2(1000) path '.'
          ) x 
     where record_code = '11102006')               
from dual;

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.07 02:30:03