Import a file to an Oracle BLOB field

Source: Internet
Author: User

Create test directories and files on the database host

$mkdir/test

$CD/test

$echo "Test Subject" >> subject.html

$echo "Test ok!" >> mail.html



Defines the file path (which is all on the database host) and authorizes

$sqlplus User/[email protected]

Sql>create or replace directory Send_file_dir as '/test ';

Sql>grant Read on directory send_file_dir to Test1;



The following is the insertion of content into the mailing table (there are two BLOB fields in the table Subject,message)

$sqlplus User/[email protected]

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, ' [email protected] ', Null,null,empty_blob (), Empty_blob (), Sysdate,null, ' Waiting ', 0, ' HTML ', null)

Returning subject,message into destloc,destmsg;--here if you have more than one BLOB field to add.

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;

/


This inserts two BLOB fields into the table email_send.

Subject field content is subject.html

Message field content is mail.html

Error message

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

Workaround

These files are on the database host and will be error-free if none of the files are on the host. Create directories and files on the host is OK, I have not found a way to read files from the remote, if any brother know, tell the next, thank you!!

This article is from the "11617433" blog, please be sure to keep this source http://11627433.blog.51cto.com/11617433/1897300

Import a file to an Oracle BLOB field

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.