将表中clob字段生成txt 文件,发现只要超过32k写入就报错。
使用UTL_FILE.PUT的方式循环将buffer写入文件,但发现一旦某个字段超过32K,在刚好超过32k便报出以上ora06512文件写入错误
v_out_filename_full := v_filedir_guid || v_out_fileext;
v_file_handle := UTL_FILE.FOPEN(v_outdir,
v_out_filename, 'w',32767);
pos := 1;
begin
LOOP
dbms_lob.read(v_clob_loc, amt, pos, buf);
-- process contents of buf
UTL_FILE.PUT(v_file_handle, buf);
UTL_FILE.FFLUSH(file => v_file_handle);
pos := pos + amt;
END LOOP;
EXCEPTION
WHEN NO_DATA_FOUND then
UTL_FILE.FCLOSE(v_file_handle);
end;
于是尝试将写入的方式改成wb 字节模式,并用UTL_FILE.PUT_RAW的模式,就可以了:
v_out_filename_full := v_filedir_guid || v_out_fileext;
v_file_handle := UTL_FILE.FOPEN(v_outdir,
v_out_filename, 'wb',32767); <<<<<<<<<<<<
pos := 1;
begin
LOOP
dbms_lob.read(v_clob_loc, amt, pos, buf);
-- process contents of buf
UTL_FILE.PUT_RAW(v_file_handle, utl_raw.cast_to_raw(buf));<<<<<<<<<<<<<<<
UTL_FILE.FFLUSH(file => v_file_handle);
pos := pos + amt;
END LOOP;
EXCEPTION
WHEN NO_DATA_FOUND then
UTL_FILE.FCLOSE(v_file_handle);
end;