create or replace directory file_dir as 'E:\test';
declare
i_blob blob;
file_handle utl_file.file_type;
v_pathna varchar2(30);
i_blob_len INTEGER;
i_amount binary_integer:=32767;
i_pos integer:=1;
i_buffer raw(32767);
str_bdnm varchar2(40);
cursor cur_rec is select * from ZZLL_BD_LSYG;
recur ZZLL_BD_LSYG%ROWTYPE;
begin
open cur_rec;
loop
fetch cur_rec into recur;
exit when cur_rec%NOTFOUND;
str_bdnm:= recur.BDNM;
select LSYG into i_blob from ZZLL_BD_LSYG where BDNM=str_bdnm;
dbms_lob.open(i_blob,dbms_lob.lob_readonly);
file_handle := utl_file.fopen('FILE_DIR',str_bdnm||'.rtf','wb',32767);
i_blob_len := dbms_lob.getlength(i_blob);
while i_pos < i_blob_len loop
DBMS_LOB.read(i_blob,i_amount,i_pos,i_buffer);
utl_file.put_raw(file_handle,i_buffer,true);
i_pos:=i_pos+i_amount;
end loop;
i_pos :=1;
dbms_lob.close(i_blob);
utl_file.fclose(file_handle);
end loop;
end;
代码中主要使用游标cursor 对数据库中的行读取选择其中的列,utl_file工具包完成文件的打开,写入,关闭操作。
操作数据表ZZLL_BD_LSYG
网友评论