随笔 - 116  文章 - 5  评论 - 1  阅读 - 14万

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   JennyYu  阅读(123)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 记一次.NET内存居高不下排查解决与启示
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示