尝试从XML
中的Oracle
文件中选择一些字段时遇到问题。
我收到以下错误:
ORA-19279:XPTY0004 - XQuery动态类型不匹配:预期的单例序列 - 得到多项序列
XML结构类似于:
<REC r_id_disclaimer="yyyyyyy">
<UID>xxxxxxx</UID>
<static_data>
<keywords count="4">
<keyword>Brain-</keyword>
<keyword>Depres</keyword>
<keyword>Acute</keyword>
<keyword>Chine</keyword>
</keywords>
我正在使用的查询如下:
select RecUid.CD_UID
, Abst2.*
from testtable2 t
cross join xmltable(xmlnamespaces(default 'http://scientific.thomsonreuters.com/schema/wok5.4/public/FullRecord'),
'records/REC'
passing t.xml_file
columns CD_UID varchar2(200) path 'UID',
--names xmltype path 'static_data/summary'
Abstract xmltype path 'static_data/fullrecord_metadata'
) RecUid
cross join xmltable(xmlnamespaces(default 'http://scientific.thomsonreuters.com/schema/wok5.4/public/FullRecord'),
'keywords/keywords'
passing RecUid.Abstract
columns keyword varchar2(200) path 'keyword'
) as Abst2
;
我已经阅读了与同一错误相关的所有其他主题,但我无法找到解决方案。我试过
columns keyword varchar2(200) path 'keyword()'
or
columns keyword varchar2(200) path 'keyword/text()'
or
columns keyword varchar2(200) path '//*keyword()'
and
columns keyword varchar2(200) path '/.keyword'
我们正在运行:
Oracle Database 11g Enterprise Edition 11.2.0.4.0 64bit Production
有人可以帮我找错吗?
谢谢!
答案 0 :(得分:2)
经过大量调整你的xml数据,并注释掉命名空间位(这使得它没有为我返回任何行),我设法得到了我认为你之后的输出:
with testtable2 as (select xmltype(
'<records>
<REC r_id_disclaimer="yyyyyyy">
<UID>xxxxxxx</UID>
<static_data>
<keywords count="4">
<keyword>Brain</keyword>
<keyword>Depres</keyword>
<keyword>Acute</keyword>
<keyword>Chine</keyword>
</keywords>
</static_data>
</REC>
</records>') xml_file from dual)
select RecUid.CD_UID,
Abst2.*
from testtable2 t
cross join xmltable(--xmlnamespaces(default 'http://scientific.thomsonreuters.com/schema/wok5.4/public/FullRecord'),
'records/REC'
passing t.xml_file
columns CD_UID varchar2(200) path 'UID',
--names xmltype path 'static_data/summary'
Abstract xmltype path 'static_data/keywords'
) RecUid
cross join xmltable(--xmlnamespaces(default 'http://scientific.thomsonreuters.com/schema/wok5.4/public/FullRecord'),
'keywords/keyword'
passing RecUid.Abstract
columns keyword varchar2(200) path '.'
) Abst2;
CD_UID KEYWORD
-------------------- --------------------
xxxxxxx Brain
xxxxxxx Depres
xxxxxxx Acute
xxxxxxx Chine