您的位置: 首页 计算机类> Oracle认证> 考试介绍
Oracle认证考试介绍,oracle dba认证,oracle题库,oracle考试试题
公务员考试辅导课程

Oracle进阶LOB字段学习(1)

发布时间:11-20

来 源:100ksw.com整理

页 数:1页

上一篇:ORACLE考试Oracle8i:备份与恢复大纲

下一篇:Oracle公司 Oracle9i DBA OCP认证新规定


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




Google
 

     

考试信息

热点

课程

更新

©2005-2006 100ksw.com 版权所有 皖ICP备06013378号