您可能会发现使用 UTL_FILE 更快,但可能不会快得多。
在我的测试中,它在大约 20k 行上略快,尽管超过 1400 万行,但它可能是值得的。
我相信,如果您想比这更快,那么要走的路是 pro*c .. 但我还没有深入了解,所以不能真正提供建议。
set pagesize 1000
set FLUSH OFF
drop user usera cascade;
create user usera default tablespace users identified by abc123;
grant create session to usera;
grant resource to usera;
create or replace directory testdir as '/tmp';
grant read,write on directory testdir to usera;
grant execute on UTL_FILE to usera;
connect usera/abc123;
set timing on
spool /tmp/spooltest.txt
select object_name from all_objects;
spool off
DECLARE
v_file UTL_FILE.FILE_TYPE;
TYPE t_col is table of all_objects.object_name%type index by PLS_INTEGER;
v_object_names t_col;
BEGIN
v_file := UTL_FILE.FOPEN('TESTDIR','utlfiletext.txt','w');
select object_name BULK COLLECT INTO v_object_names
from all_objects;
for idx IN 1 .. v_object_names.COUNT LOOP
UTL_FILE.PUT_LINE(v_file, v_object_names(idx), FALSE);
END LOOP;
UTL_FILE.FCLOSE(v_file);
END;
/
结果。顶部结果仅来自 sqlplus,底部使用 UTL_FILE
23931 rows selected.
Elapsed: 00:00:06.60
PL/SQL procedure successfully completed.
Elapsed: 00:00:05.45