问题描述
我正在尝试读取具有多个名称空间的xml clob文件。我只是个想法,花了几个小时。
我的测试用例如下:
declare
test_msg clob;
begin
test_msg := to_clob(
'
<testReq xmlns="http://test/xxx/xxx-xxx/v1">
<id>HelloWorld</id>
<numer>HelloWorld</numer>
<typ>COGR</typ>
<czyAktywny>T</czyAktywny>
<a:fieldone xmlns:a="http://xxx/yyy/zzz/v1">
<a:sym>HelloWorld</a:sym>
<a:sympod>HelloWorld</a:sympod>
</a:fieldone>
</testReq>
'
);
-- Call the function
:result := i_mypackage_pkg.odbierzReq(p_komunikatWej => test_msg,p_logId => 12344);
end;
我的xml_table实现如下:
from xmltable(xmlnamespaces('http://test/xxx/xxx-xxx/v1' as "model",'http://xxx/yyy/zzz/v1' as "adres"),'//model:testReq' passing xmlType(p_komunikatWej)
columns
id varchar2(20 char) path 'model:id',numer varchar2(20 char) path 'model:numer',typ varchar2(20 char) path 'model:typ',czyAktywny varchar2(1 char) path 'model:czyAktywny'
-- dane adresowe punktu poboru,kod varchar2(7 char) path 'adres:fieldone/a:sympod'
) t;
异常看起来像这样:
XVM-01081: [XPST0081] Invalid prefix
1 declare namespace model="http://test/xxx/xxx-xxx/v1";declare namesp
- ^
我真的没有主意。任何帮助,将不胜感激。谢谢
'http://xxx/yyy/zzz/v1' as "a"
解决方法
除了始终如一地使用a
/ adres
之外,您还可以通过声明默认名称空间而不是添加model
来简化路径:
from xmltable(xmlnamespaces(default 'http://test/xxx/xxx-xxx/v1','http://xxx/yyy/zzz/v1' as "a"),'/testReq' passing xmlType(p_komunikatWej)
columns
id varchar2(20 char) path 'id',numer varchar2(20 char) path 'numer',typ varchar2(20 char) path 'typ',czyAktywny varchar2(1 char) path 'czyAktywny'
-- dane adresowe punktu poboru,kod varchar2(7 char) path 'a:fieldone/a:sympod'
) t;
db<>fiddle demo使用CTE代替PL / SQL。