--载入图片到数据库
declare
alob blob;
afile bfile;
amount int;
src_offset int := 1;
dest_offset int := 1;
begin
select photo into alob from photo_tab for update;
afile := bfilename('G', 'a.jpg');
dbms_lob.fileopen(afile, 0);
amount := dbms_lob.getlength(afile);
dbms_lob.loadblobfromfile(alob, afile, amount, dest_offset, src_offset);
dbms_lob.fileclose(afile);
commit;
end;
/
--从数据库读取图片到文件.
declare
alob blob;
amount int;
offset int := 1;
totalw int := 0;
currentw int;
buffer raw(2000);
f utl_file.file_type;
begin
select photo into alob from photo_tab ;
amount := dbms_lob.getlength(alob);
f := utl_file.fopen('G', 'b.jpg', 'ab', 2000);
loop
if ((amount - totalw) >= 2000) then
currentw := 2000;
else
currentw := amount - totalw;
end if;
dbms_lob.read(alob, currentw, totalw + 1, buffer);
utl_file.put_raw(f, buffer);
totalw := totalw + currentw;
exit when totalw = amount;
end loop;
utl_file.fclose(f);
end;
/