|
--插入bfile
create or replace procedure insert_book(filename varchar2) as
book_file bfile := null;
bookexists boolean := false;
begin
book_file := bfilename(’book_text’, filename);
bookexists := dbms_lob.fileexists(book_file) = 1;
if bookexists then
insert into my_book_files values ((select count(*) from my_book_files) + 1 , book_file);
dbms_output.put_line(’insert sucess! file : ’ || filename);
else
dbms_output.put_line(’not exists! file : ’ || filename);
end if;
exception
when dbms_lob.noexist_directory then
dbms_output.put_line(’error: ’ || sqlerrm);
when dbms_lob.invalid_directory then
dbms_output.put_line(’error : ’ || sqlerrm);
when others then
dbms_output.put_line(’unkown error : ’ || sqlerrm);
end insert_book;
/
create or replace procedure insertpdf(filename varchar2) is
fileloc bfile;
nid number;
npdfsize integer;
bfileexists boolean := false;
begin
fileloc := bfilename(’pdfdir’,filename);
bfileexists := dbms_lob.fileexists(fileloc) = 1;
if bfileexists = false then
dbms_output.put_line(filename || ’ not exists’);
return;
end if;
npdfsize := dbms_lob.getlength(fileloc);
dbms_output.put_line(’the length of ’ || filename || ’ is ’ || npdfsize);
select count(*) + 1 into nid from pdftable;
insert into pdftable(id,pdffile)
values (nid, fileloc);
exception
when dbms_lob.noexist_directory then
dbms_output.put_line(’error: ’ || sqlerrm);
when dbms_lob.invalid_directory then
dbms_output.put_line(’error : ’ || sqlerrm);
when others then
dbms_output.put_line(’unkown error : ’ || sqlerrm);
end;
/
--插入 blob
create or replace procedure insertimg(imgname varchar2) is
v_file_loc bfile;
v_image blob;
nid number;
nimgsize integer;
bfileexists boolean := false;
begin
v_file_loc := bfilename(’imagedir’, imgname);
bfileexists := dbms_lob.fileexists(v_file_loc) = 1;
if bfileexists = false then
dbms_output.put_line(imgname || ’ not exists’);
return;
end if;
nimgsize := dbms_lob.getlength(v_file_loc);
dbms_output.put_line(imgname ||’ size is ’ || nimgsize);
dbms_output.put_line(’now inserting empty image row’);
select count(*) + 1 into nid from imagetable;
insert into imagetable(id, image)
values (nid, empty_blob)
returning image into v_image;
dbms_lob.fileopen (v_file_loc);
dbms_output.put_line(’open file’);
dbms_lob.loadfromfile(v_image, v_file_loc, nimgsize);
dbms_lob.fileclose(v_file_loc);
commit;
exception
when others then
dbms_output.put_line(’error happen! ’ || sqlerrm);
dbms_lob.fileclose(v_file_loc);
end insertimg;
/
|