Here is an example of how to do it using Oracle Application Server:
Loading an image into a BLOB column and displaying it via OAS
--------------------------
The steps are as follows:
Step 1.
-------
Create a table to store the blobs:
create table blobs
(
id varchar2(255),
blob_col blob
);
Step 2.
-------
Create a logical directory in the database to the physical file system:
create or replace directory MY_FILES as 'c:\images';
Step 3.
-------
Create a procedure to load the blobs from the file system using the logical
directory.
create or replace procedure insert_img (p_id VARCHAR2, p_filename VARCHAR2)
as
f_lob bfile;
b_lob blob;
begin
insert into blobs values ( p_id, empty_blob() )
return blob_col into b_lob;
f_lob := bfilename( 'MY_FILES', p_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;
/
Load the images into the database by calling the procedure (these files must first exist on the ORACLE Server in c:\images directory):
EXEC insert_img ('image1', 'my_image1.gif');
EXEC insert_img ('image2', 'my_image2.gif');
etc.
Step 4.
-------
Create a procedure that is called via Oracle Application Server to display the
image.
create or replace procedure get_img as
vblob blob;
buffer raw(32000);
buffer_size integer := 32000;
offset integer := 1;
length number;
begin
owa_util.mime_header('imag
select blob_col into vblob from blobs where id = 'MyGif';
length := dbms_lob.getlength(vblob);
while offset < length loop
dbms_lob.read(vblob, buffer_size, offset, buffer);
htp.prn(utl_raw.cast_to_va
offset := offset + buffer_size;
end loop;
exception
when others then
htp.p(sqlerrm);
end;
/
Step 5.
-------
Use the PL/SQL cartridge to call the get_img procedure
OR
Create that procedure as a function and invoke it within your PL/SQL code to
place the images appropriately on your HTML page via the PL/SQL toolkit.
Main Topics
Browse All Topics





by: konektorPosted on 2002-06-24 at 01:40:32ID: 7103118
u must have table with BLOB column. Oracle can store up to 4GB of binary data in such column. u also store it into long column, but u have as big buffer as image u want to store. if u use BLOB column, u can store binary data piece after piece.
as for accessing table with BLOB column, u can do it via ODBC. but as I know, only oracle ODBC driver enables manipulating BLOB data.