根据UTL_FILE导出数据库某个表的所有列存储过程:
create or replace procedure pmsreport as
CURSOR c1 IS
SELECT invoice_item_id,item_name FROM pms;
CURSOR c1 IS
SELECT invoice_item_id,item_name FROM pms;
item_id pms.item_id%TYPE;
item_name pms.item_name%TYPE;
item_name pms.item_name%TYPE;
OutputRecord varchar2(255);
OutputFile utl_file.file_type;
OutputFile utl_file.file_type;
BEGIN
open c1;
fetch c1 into item_id,item_name;
open c1;
fetch c1 into item_id,item_name;
OutputFile:=utl_file.fopen(UPPER('RECV_AREA'),'pmsreport.csv','w',32767);
WHILE c1%FOUND LOOP
OutputRecord := item_id||','||item_name;
utl_file.put(OutputFile,OutputRecord);
utl_file.new_line(OutputFile);
FETCH c1 INTO item_id,item_name;
END LOOP;
OutputRecord := item_id||','||item_name;
utl_file.put(OutputFile,OutputRecord);
utl_file.new_line(OutputFile);
FETCH c1 INTO item_id,item_name;
END LOOP;
CLOSE c1;
utl_file.fclose(OutputFile);
END;
utl_file.fclose(OutputFile);
END;
测试某表两列数据1900万行5分钟导出。
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/16381228/viewspace-759095/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/16381228/viewspace-759095/
本文介绍了一个使用Oracle PL/SQL中UTL_FILE包来导出数据库表所有列到CSV文件的存储过程。该过程通过游标遍历指定表的记录,并将每条记录写入CSV文件。经测试,对于包含1900万行数据的表,整个导出过程仅需约5分钟。
5万+

被折叠的 条评论
为什么被折叠?



