在數據庫主機上創建測試目錄及文件
$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,'[email protected]',null,null,empty_blob(),empty_blob(),sysdate,null,'waiting',0,'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了,我暫時還沒找到從遠程上讀取文件的方法,如果哪位兄弟知道的話,告訴下,謝謝!!