hi,

I have a table emp1 with emp_id and pic fields.
I was able to insert images in to pic(BLOB) column.
Now I want to retrieve the image of an employee with a given emp_id in to an external file.

I have created a directory as below...

create or replace directory blobs as 'c:\db_files';

The below is the procedure I am using to get the image from table to a file...

CREATE OR REPLACE PROCEDURE display_image
IS
v_file UTL_FILE.FILE_TYPE;
v_buffer RAW(32767);
v_amount BINARY_INTEGER := 32767;
v_pos INTEGER :=1;
v_blob BLOB;
v_blob_len INTEGER;

BEGIN

SELECT pic INTO v_blob FROM emp1
WHERE emp_id = 1;

v_blob_len := DBMS_LOB.GETLENGTH(v_blob);
DBMS_OUTPUT.PUT_LINE('THE LENGTH OF BLOB IS '|| v_blob_len);

v_file := UTL_FILE.FOPEN('BLOBS','MyImage.jpg','w',32767);

WHILE v_pos < v_blob_len LOOP
DBMS_LOB.READ(v_blob, v_amount, v_pos, v_buffer);
UTL_FILE.PUT_RAW(v_file,v_buffer,TRUE);
v_pos := v_pos + v_amount;
END LOOP;

UTL_FILE.FCLOSE(v_file);

EXCEPTION
WHEN OTHERS THEN

IF UTL_FILE.IS_OPEN(v_file) THEN
UTL_FILE.FCLOSE(v_file);
END IF;
RAISE;
END;
/

When I execute this procedure, and open the file in the specified directory, the image which I have inserted is not seen.Some colours with distortions is seen.

Please help with this problem.

Thanks in advance
sudhav17