$mkdir /test
$cd /test
$echo "Test Subject" >> subject.html
$echo "test ok !" >> mail.html
$sqlplus user/passwd@instance
sql>create or replace directory send_file_dir as '/test';
sql>grant read on directory send_file_dir to test1;
如下是向发邮件的表中插入内容(表中有两个blob字段subject,message)
$sqlplus user/passwd@instance
sql>declare
destloc blob;
destmsg blob;
srcfile bfile:=BFILENAME('SEND_FILE_DIR','subject.html');
msgfile bfile:=BFILENAME('SEND_FILE_DIR','mail.html');
BEGIN
insert into email_send values (seq_email_id.nextval,null,'test@163.com',empty_blob(),sysdate,'waiting','HTML',null)
returning subject,message into destloc,destmsg; --这里如果有多个blob字段再增加。
dbms_lob.fileopen(srcfile);
dbms_lob.loadfromfile(destloc,srcfile,dbms_lob.getlength(srcfile));
dbms_lob.fileclose(srcfile);
dbms_lob.fileopen(msgfile);
dbms_lob.loadfromfile(destmsg,msgfile,dbms_lob.getlength(msgfile));
dbms_lob.fileclose(msgfile);
commit;
END;
/
这样就向表email_send插入了两个blob字段。
subject字段内容为subject.html
message字段内容为mail.html
报错信息
ERROR at line 1:
ORA-22288: file or LOB operation FILEOPEN Failed
No such file or directory
ORA-06512: at "SYS.DBMS_LOB",line 805
ORA-06512: at line 9
这些文件都是在数据库主机上的,如果主机上没有这些文件都会报错。在主机上创建目录及文件就ok了,我暂时还没找到从远程上读取文件的方法,如果哪位兄弟知道的话,告诉下,谢谢!!
原文链接:https://www.f2er.com/oracle/210563.html