How to insert images into an Oracle database table

Source: Internet
Author: User

Some students need to insert images into the table in their projects. The following provides a method for your reference:

1. Create a table. Note: The columns to insert images must be defined as BLOB.

Create table image_lob (t_id varchar2 (5) not null, t_image blob not null );

2. Create an image directory named images.

Create or replace directory "images" as 'f: \ pic \';

3. Create a storage process. filenameis the image name, for example, 'cat.jpg'

Create or replace procedure img_insert (tid varchar2, filename varchar2)
F_lob bfile;
B _lob blob;
Begin
Insert into image_lob (t_id, t_image)
Values (tid, empty_blob () return t_image into B _lob;
F_lob: = bfilename ('images', filename );
Dbms_lob.fileopen (f_lob, dbms_lob.file_readonly );
Dbms_lob.loadfromfile (B _lob, f_lob,
Dbms_lob.getlength (f_lob ));
Dbms_lob.fileclose (f_lob );
Commit;
End;
/

4. Execute the above stored procedure to insert Images

Exec img_insert('1', 'cat.jpg ');


5. View tables

Select * from image_lob;

Related Article

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.