Showing GIF's etc to the Web


To retrieve a GIF image from a database column and present it to a web page the following PL/SQL routine may be useful. We use DBMS_LOB to read the image content in 4k chunks and UTL_RAW.CAST_TO_VARCHAR2 to allow use within the standard HTP routines.

create or replace package image_get as
	procedure gif( p_id in demo.id%type );
end;
/

create or replace package body image_get as

procedure gif( p_id in demo.id%type )is
	l_lob	blob;
	l_amt	number default 30;
	l_off   number default 1;
	l_raw   raw(4096);
begin
	select theBlob into l_lob
  	  from demo 
     where id = p_id;

	owa_util.mime_header( 'image/gif' );

	begin
		loop
			dbms_lob.read( l_lob, l_amt, l_off, l_raw );
			htp.prn( utl_raw.cast_to_varchar2( l_raw ) );
			l_off := l_off+l_amt;
			l_amt := 4096;
		end loop;
	exception
		when no_data_found then 
			NULL;
	end;
end;

end;
/



See the original newsgroup post here