--插入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;
/