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;