向oracle的blob字段导入文件-成都创新互联网站建设

关于创新互联

多方位宣传企业产品与服务 突出企业形象

公司简介 公司的服务 荣誉资质 新闻动态 联系我们

向oracle的blob字段导入文件

在数据库主机上创建测试目录及文件

创新互联专注于普陀企业网站建设,响应式网站设计,商城建设。普陀网站建设公司,为普陀等地区提供建站服务。全流程按需求定制制作,专业设计,全程项目跟踪,创新互联专业和态度为您提供的服务

$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

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 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了,我暂时还没找到从远程上读取文件的方法,如果哪位兄弟知道的话,告诉下,谢谢!!


当前标题:向oracle的blob字段导入文件
本文路径:http://kswsj.cn/article/jphdgh.html

其他资讯