我想知道有什么方法可以让我把xml文件作为数据库吗?
我的代码
select t.extract('/S/@ID').getstringval() as s
FROM
TABLE(
XMLSEQUENCE(
(select xmltype('<?xml version="1.0"?>
<SERIAL>
<S ID="1E0100057107" />
<S ID="1E0100057108" />
<S ID="1E0100057109" />
<S ID="1E0100057110" />
</SERIAL>').extract( '//S' ) from dual)
))T;
desired output
S
-------------------------
1E0100057107,1E0100057108,1E0100057109,1E0100057110
谢谢..
答案 0 :(得分:0)
使用LISTAGG
功能(支持最多4000个字符串)
select LISTAGG(t.extract('/S/@ID').getstringval(),',') WITHIN GROUP (ORDER BY 1) as s
FROM
TABLE(
XMLSEQUENCE(
(select xmltype('<?xml version="1.0"?>
<SERIAL>
<S ID="1E0100057107" />
<S ID="1E0100057108" />
<S ID="1E0100057109" />
<S ID="1E0100057110" />
</SERIAL>').extract( '//S' ) from dual)
))T;
或XMLAGG
select xmlagg(xmlelement(e, t.extract('/S/@ID').getstringval()|| ',')).extract('//text()').extract('//text()')
FROM
TABLE(
XMLSEQUENCE(
(select xmltype('<?xml version="1.0"?>
<SERIAL>
<S ID="1E0100057107" />
<S ID="1E0100057108" />
<S ID="1E0100057109" />
<S ID="1E0100057110" />
</SERIAL>').extract( '//S' ) from dual)
))T;