save clob to file
Hi,
I use the below plsql to save clob field into file, the code save the first 8-10 files in about 2 seconds and after that,
it run slower and slower, about 10 file in 1 minutes, anyone can help to point out what could be the cause?
Thanks
Vincent
create or replace procedure save_xml_log_to_file(vso in varchar2,vstation in varchar2)
is
l_file utl_file.file_type;
l_buffer raw(32767);
-- l_buffer varchar2(32767);
l_amount binary_integer := 32767;
l_pos integer := 1;
l_blob blob;
l_blob_len integer;
myfile_name varchar2(250);
cursor cl is
select c.filename from cust_test_log c,tracking t where t.sn=c.sn and t.so=vso and t.ticket=c.ticket and t.station=vstation;
begin
for i in cl loop
-- Get LOB locator
select clob_to_blob(c.test_log_text), c.filename
into l_blob, myfile_name
from cust_test_log c
where c.filename=i.filename;
-- l_blob := i.test_log;
-- myfile_name := i.filename;
l_blob_len := dbms_lob.getlength(l_blob);
l_pos := 1; --re-init l_pos var
-- Open the destination file.
l_file := utl_file.fopen('XML_LOG', myfile_name, 'wb', 32767);
-- Read chunks of the BLOB and write them to the file
-- until complete.
while l_pos < l_blob_len
loop
dbms_lob.read(l_blob, l_amount, l_pos, l_buffer);
utl_file.put_raw(l_file, l_buffer, true);
l_pos := l_pos + l_amount;
end loop;
-- Close the file.
utl_file.fclose(l_file);
end loop;
exception
when others then
-- Close the file if something goes wrong.
if utl_file.is_open(l_file) then
utl_file.fclose(l_file);
end if;
raise;
end save_xml_log_to_file;