使用存储过程向Oracle数据库中插入BLOB文件

这段时间在做扬子石化的GIS开发,一直以来遇到一个最大的问题就是上传大文件类型(BLOB)超过32K就会从数据库中报出错来,十分头痛,前天在网上看到一个解决方案,是用SQL语句在界面中先插入一个empty_blob(),再通过update语句更新,感觉虽然解决问题,但一直觉得不是很方便,也不符合现在程序中使用三层架构在后台处理数据的要求,所以想了想,改成了存储过程,并且进行了简化,用一条语句实现了insert或是update,现把代码发出来跟大家共享一下,也请大家指点指点:

create   or   replace   procedure  MyPre_IMPORTMap(nMapid  in   varchar2 ,
 nFilename 
in   varchar2 , nFilecon out blob,nlastfile  in   number ,
 nfilelevel 
in   number  ) is
 
 num 
number ;
 recordnum 
number ;
 
begin
  
select  SEQ_SYS_FILE_NUM.NEXTVAL  into  num  from  dual;
  
select   count (sys_file.file_num)  into  recordnum  from  sys_file
  
where  sys_file. file_name   =  nFilename  and  sys_file.map_id  =  nMapid;
  
if  recordnum  >   0   then
  
begin
       
update  sys_file  set  sys_file.file_con  =  empty_blob()
       
where  sys_file. file_name   =  nFilename
       
and  sys_file.map_id  =  nMapid
       returning sys_file.file_con
       
into  nFilecon;
  
end ; else
  
begin
       
insert   into  sys_file  values (num,nMapid,nFilename,empty_blob(),
       nlastfile,nfilelevel)
       returning sys_file.file_con
       
into  nFilecon;
 
end ; end   if ;
end  MyPre_IMPORTMap;


 

你可能感兴趣的:(使用存储过程向Oracle数据库中插入BLOB文件)