Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

save clob to file

pjsiong-JavaNetApr 11 2011 — edited Dec 6 2012
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;
This post has been answered by odie_63 on Apr 12 2011
Jump to Answer

Comments

Processing
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Jan 3 2013
Added on Apr 11 2011
10 comments
6,695 views