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/的默认命名空间下,空默认值会导致节点匹配失败。
修正方案
如果要提取
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;
如果要提取/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
相关产品推荐
相关产品推荐

