$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;
$sqlplus user/passwd@instance
SQL>declare
destlocblob;
destmsg blob;
srcfilebfile:=BFILENAME('SEND_FILE_DIR','subject.html');
msgfilebfile:=BFILENAME('SEND_FILE_DIR','mail.html');
BEGIN
insert into email_send values (seq_email_id.nextval,null,'test@163.com',null,null,empty_blob(),empty_blob(),sysdate,null,'waiting',0,'HTML',null)
returning
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了,我暂时还没找到从远程上读取文件的方法,如果哪位兄弟知道的话,告诉下,谢谢!!
: