Oracle常用脚本

经常忘记一些oracle语法,在此做一下记录吧,每逢遇到新的脚本,就记录在此。

1. 通过存储过程的方式,将图片插入blob字段,

创建目录并授权

create directory  D_FILE as '/home/oracle/';

grant read,write to scott;

创建存储过程:传入参数:tg_id 为要插入表的id,tg_filename为要插入的文件名

实现将文件插入到表t_lob的字段c1中。

表t_lob的结构:create table t_lob(id varchar2(100),c1 blob);

create procedure p_t_lob(tg_id varchar2 ,tg_filename VARCHAR2) is
l_bfile bfile;
l_blob blob;
begin
update t_lob set c1=empty_blob() where ID=tg_id
return c1 into l_blob;
l_bfile:=bfilename('D_FILE',tg_filename);
dbms_lob.open(l_bfile,dbms_lob.file_readonly);
dbms_lob.loadfromfile(l_blob,l_bfile,dbms_lob.getlength(l_bfile));
dbms_lob.close(l_bfile);
commit;
end;
/

 

posted on 2022-12-02 09:29  JennyYu  阅读(116)  评论(0编辑  收藏  举报