Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.server -> Re: Saving images in Oracle 8i
Storing an image is quite involved, but once you get the hang of it
it's fairly straight-forward.
I am storing images in a V806 database, the application can view them
and I'm not sure how that bit of it works, but I don't think it's too
hard.
In order to store them in the database (without Intermedia, I've never used that), you need to create a location to keep the image files and an Oracle DIRECTORY to point to that. You obviously need a TABLE, and that table needs to have a BLOB datatype.
Before you can insert an image, you need to insert an empty value into the BLOB field and then call a procedure to insert the image. Copy the image file to the directory, then run the SQL below. You may need to make sure the file permissions are correct.
REM
REM Create the directory
create or replace directory BLOBDIR as '/app/oradata/blobdir';
REM Create the Table
create table blobtab
(REFNO NUMBER(3),
BLOB_DATA BLOB);
REM Insert a dummy row
insert into blobtab values
('001',empty_blob());
REM Run the Procedure to insert the image
set serveroutput on
declare
ablob blob; abfile bfile := bfilename('BLOBDIR','the_name_of_your_image.jpg'); amount integer; asize integer; begin select blob_data into ablob from blobtab where refno='001' for update; dbms_lob.fileopen(abfile); asize := dbms_lob.getlength(abfile); dbms_output.put_line('Size of input file: ' || asize); dbms_lob.loadfromfile(ablob, abfile, asize); dbms_output.put_line('After loadfromfile'); asize := dbms_lob.getlength(ablob); dbms_output.put_line('Size of blob: ' || asize); exception when others then dbms_output.put_line('An exception occurred'); dbms_output.put_line(sqlcode || sqlerrm);end;
![]() |
![]() |