[英]Generate XML files from Oracle query
I have a query which return 50 millions rows.我有一个返回 5000 万行的查询。 I want to generate XML files for each row (file max. size is 100k).我想为每一行生成 XML 文件(文件最大大小为 100k)。 Of course I know the tags but I don't know how to write this in the most efficient way.我当然知道标签,但我不知道如何以最有效的方式编写它。 Any help?有什么帮助吗?
Thanks谢谢
I wouldn't recommend trying to write 50M files to disk, but here's some code you can play with to demonstrate why its not a good idea我不建议尝试将 50M 文件写入磁盘,但是您可以使用以下代码来演示为什么这不是一个好主意
1: a function that writes files to disk using a directory 1:使用目录将文件写入磁盘的 function
create or replace function WRITETOFILE (dir in VARCHAR2,fn in VARCHAR2, dd IN clob) return clob AS
ff UTL_FILE.FILE_TYPE;
l_amt number := 30000;
l_offset number := 1;
l_length number := nvl(dbms_lob.getlength(dd),0);
buf varchar2(30000);
begin
ff := UTL_FILE.FOPEN(dir,fn,'W',32760);
while ( l_offset < l_length ) loop
buf := dbms_lob.substr(dd,l_amt,l_offset);
utl_file.put(ff, buf);
utl_file.fflush(ff);
utl_file.new_line(ff);
l_offset := l_offset+length(buf);
end loop;
UTL_FILE.FCLOSE(ff);
return dd;
END WRITETOFILE;
/
2: statement creating a table with all rows from a query that makes use of function above - suggesting that you keep the number of rows small to see how it plays 2:使用上述 function 的查询创建包含所有行的表的语句 - 建议您保持较小的行数以查看其运行方式
create table tmptbl as
select writetofile('DMP_DIR','xyz-'||level||'.xml', xmlelement("x", level).getClobVal()) tmpcol, systimestamp added_at
from dual CONNECT BY LEVEL <= 10;
3: drop table to repeat create table statement with more rows 3:删除表以重复创建具有更多行的表语句
drop table tmptbl purge;
I did 10k files in 10 seconds - which would give 1000 seconds for 1M files and 50000 seconds for 50M files (ie just under 14 hours).我在 10 秒内完成了 10k 个文件 - 1M 文件需要 1000 秒,50M 文件需要 50000 秒(即不到 14 小时)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.