我已将xml导入oracle,我正在使用列类型Xmltype。
这是xml的结构:
<Release>
<ReleaseId>
<GRid>A10320WA0003483489</GRid>
<ICPN IsEan="false">3610151317086</ICPN>
<CatalogNumber Namespace="UPC">3610151317086</CatalogNumber>
<ProprietaryId Namespace="ADAM_ID">551247405</ProprietaryId>
</ReleaseId>
<ReleaseReference>R551247405</ReleaseReference>
<ReferenceTitle>
<TitleText>Tony Bennett: 101 Hits - I Left My Heart in San Francisco</TitleText>
</ReferenceTitle>
<ReleaseResourceReferenceList>
<ReleaseResourceReference>A551248137</ReleaseResourceReference>
<ReleaseResourceReference>A551248136</ReleaseResourceReference>
<ReleaseResourceReference>A551248070</ReleaseResourceReference>
<ReleaseResourceReference>A551248074</ReleaseResourceReference>
<ReleaseResourceReference>A551248041</ReleaseResourceReference>
<ReleaseResourceReference>A551247836</ReleaseResourceReference>
</ReleaseResourceReferenceList>
这是我正在使用的选择
select extractvalue(value (sr),'*/ReleaseId/ISRC') as ISRC
,extractvalue( value (sr),'*/ReleaseId/GRid' )as GRid
,extractvalue( value (sr),'*/ReleaseId/ICPN' )as ICPN
,extractvalue( value (sr),'*/ReleaseId/CatalogNumber' )as CatalogNumber
,extractvalue( value (sr),'*/ReleaseId/ProprietaryId' )as ProprietaryId
,extractvalue( value (sr),'*/ReferenceTitle/TitleText' )as TitleText
,extractvalue( value (sr),'*/ReleaseType' )as ReleaseType
,extractvalue( value (st),'*/ReleaseResourceReference' )as teste
from xml_ddex x,
table(xmlsequence (extract(dados, '*/ContainedReleaseList/Release' )))sr,
table(xmlsequence(extract(value(sr),'*/ReleaseResourceReferenceList')))st
任何人都可以帮助我吗?感谢
答案 0 :(得分:1)
根据您对数据和预期结果的一些猜测事实,这可能是您之后的查询:
select --+ no_merge(SR)
SR.isrc, SR.grid, SR.icpn, SR.catalog_number, SR.proprietary_id, SR.title_text, SR.release_type,
ST.rel_res_ref as teste
from xml_ddex X
cross join xmltable(
'*/ContainedReleaseList/Release'
passing X.dados
columns
rel_res_ref_list$ xmltype path '/Release/ReleaseResourceReferenceList',
ISRC varchar2(200) path '/Release/ReleaseId/ISRC',
GRid varchar2(200) path '/Release/ReleaseId/GRid',
ICPN varchar2(200) path '/Release/ReleaseId/ICPN',
catalog_number varchar2(200) path '/Release/ReleaseId/CatalogNumber',
proprietary_id varchar2(200) path '/Release/ReleaseId/ProprietaryId',
title_text varchar2(200) path '/Release/ReferenceTitle/TitleText',
release_type varchar2(200) path '/Release/ReleaseType'
) SR
cross join xmltable(
'/ReleaseResourceReferenceList/ReleaseResourceReference'
passing SR.rel_res_ref_list$
columns
rel_res_ref varchar2(200) path '/ReleaseResourceReference'
) ST
;
我对no_merge
提示感到抱歉。在我的测试环境中,我无法在没有提示的情况下使查询正常工作;它抛出ORA-600
例外。
对某些部分猜测的XML进行测试......
with xml_ddex as (
select xmltype('<?xml version="1.0" ?>
<SomeRootElementIGuessThereIs>
<ContainedReleaseList>
<Release>
<ReleaseId>
<GRid>A10320WA0003483489</GRid>
<ICPN IsEan="false">3610151317086</ICPN>
<CatalogNumber Namespace="UPC">3610151317086</CatalogNumber>
<ProprietaryId Namespace="ADAM_ID">551247405</ProprietaryId>
</ReleaseId>
<ReleaseReference>R551247405</ReleaseReference>
<ReferenceTitle>
<TitleText>Tony Bennett: 101 Hits - I Left My Heart in San Francisco</TitleText>
</ReferenceTitle>
<ReleaseResourceReferenceList>
<ReleaseResourceReference>A551248137</ReleaseResourceReference>
<ReleaseResourceReference>A551248136</ReleaseResourceReference>
<ReleaseResourceReference>A551248070</ReleaseResourceReference>
<ReleaseResourceReference>A551248074</ReleaseResourceReference>
<ReleaseResourceReference>A551248041</ReleaseResourceReference>
<ReleaseResourceReference>A551247836</ReleaseResourceReference>
</ReleaseResourceReferenceList>
</Release>
<Release>
<ReleaseId>
<GRid>A10320WA0003483489</GRid>
<ICPN IsEan="false">3610151317086</ICPN>
<CatalogNumber Namespace="UPC">3610151317086</CatalogNumber>
<ProprietaryId Namespace="ADAM_ID">551247405</ProprietaryId>
</ReleaseId>
<ReleaseReference>R551247405</ReleaseReference>
<ReferenceTitle>
<TitleText>Tony Bennett: 102 Hits - I Left My Head in Fresno</TitleText>
</ReferenceTitle>
<ReleaseResourceReferenceList>
<ReleaseResourceReference>A551248137</ReleaseResourceReference>
<ReleaseResourceReference>A551248136</ReleaseResourceReference>
<ReleaseResourceReference>A551248070</ReleaseResourceReference>
<ReleaseResourceReference>A551248074</ReleaseResourceReference>
<ReleaseResourceReference>A551248041</ReleaseResourceReference>
<ReleaseResourceReference>A551247836</ReleaseResourceReference>
</ReleaseResourceReferenceList>
</Release>
</ContainedReleaseList>
</SomeRootElementIGuessThereIs>'
) as dados
from dual
)
select --+ no_merge(SR)
SR.isrc, SR.grid, SR.icpn, SR.catalog_number, SR.proprietary_id, SR.title_text, SR.release_type,
ST.rel_res_ref as teste
from xml_ddex X
cross join xmltable(
'*/ContainedReleaseList/Release'
passing X.dados
columns
rel_res_ref_list$ xmltype path '/Release/ReleaseResourceReferenceList',
ISRC varchar2(200) path '/Release/ReleaseId/ISRC',
GRid varchar2(200) path '/Release/ReleaseId/GRid',
ICPN varchar2(200) path '/Release/ReleaseId/ICPN',
catalog_number varchar2(200) path '/Release/ReleaseId/CatalogNumber',
proprietary_id varchar2(200) path '/Release/ReleaseId/ProprietaryId',
title_text varchar2(200) path '/Release/ReferenceTitle/TitleText',
release_type varchar2(200) path '/Release/ReleaseType'
) SR
cross join xmltable(
'/ReleaseResourceReferenceList/ReleaseResourceReference'
passing SR.rel_res_ref_list$
columns
rel_res_ref varchar2(200) path '/ReleaseResourceReference'
) ST
;
......收益......
A10320WA0003483489 3610151317086 3610151317086 551247405 Tony Bennett: 101 Hits - I Left My Heart in San Francisco A551248137
A10320WA0003483489 3610151317086 3610151317086 551247405 Tony Bennett: 101 Hits - I Left My Heart in San Francisco A551248136
A10320WA0003483489 3610151317086 3610151317086 551247405 Tony Bennett: 101 Hits - I Left My Heart in San Francisco A551248070
A10320WA0003483489 3610151317086 3610151317086 551247405 Tony Bennett: 101 Hits - I Left My Heart in San Francisco A551248074
A10320WA0003483489 3610151317086 3610151317086 551247405 Tony Bennett: 101 Hits - I Left My Heart in San Francisco A551248041
A10320WA0003483489 3610151317086 3610151317086 551247405 Tony Bennett: 101 Hits - I Left My Heart in San Francisco A551247836
A10320WA0003483489 3610151317086 3610151317086 551247405 Tony Bennett: 102 Hits - I Left My Head in Fresno A551248137
A10320WA0003483489 3610151317086 3610151317086 551247405 Tony Bennett: 102 Hits - I Left My Head in Fresno A551248136
A10320WA0003483489 3610151317086 3610151317086 551247405 Tony Bennett: 102 Hits - I Left My Head in Fresno A551248070
A10320WA0003483489 3610151317086 3610151317086 551247405 Tony Bennett: 102 Hits - I Left My Head in Fresno A551248074
A10320WA0003483489 3610151317086 3610151317086 551247405 Tony Bennett: 102 Hits - I Left My Head in Fresno A551248041
A10320WA0003483489 3610151317086 3610151317086 551247405 Tony Bennett: 102 Hits - I Left My Head in Fresno A551247836