Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Export multiple blobs to jpg

FynixJul 6 2015 — edited Jul 11 2015

Hello folks,

     I am currently trying to figure out how to implement the procedure to extract one image https://oracle-base.com/articles/9i/export-blob-9i and apply to multiple images (over 1000). I have searched through the forums and found multiple references to that example but none really explains how to apply for multiple rows. I am not skilled in PL/SQL but I have programming experience and I have edited the procedure to name the file according to a unique number but I am at a loss of how to apply for more than one record.

create or replace procedure write_blob is

l_file UTL_FILE.FILE_TYPE;

l_buffer RAW(32767);

l_amount BINARY_INTEGER := 32767;

l_pos INTEGER := 1;

l_blob BLOB;

empidnum varchar2(10);

l_blob_len INTEGER;

-- Get LOB locator

SELECT

E.ID,

M.GRAPHIC into empidnum, l_blob

FROM

EMPLOYEES E, LINKIMAGE LM, MASTERIMAGE M

WHERE

E.IDNUM = LM.FKTABLE

AND LM.FK = M.IMGNUM

AND LM.TYPE = 'ID'

AND E.ID = 'BX22563'

ORDER BY E.ID;

-- Establish length of BLOB

l_blob_len := DBMS_LOB.getlength(l_blob);

-- Open the destination file.

l_file := UTL_FILE.fopen('BLOB_DIR',empidnum||'.jpg','w', 32767);

-- Read chunks of the BLOB and write them to the file until complete.

WHILE l_pos < l_blob_len LOOP

DBMS_LOB.read(l_blob, l_amount, l_pos, l_buffer);

UTL_FILE.put_raw(l_file, l_buffer, TRUE);

l_pos := l_pos + l_amount;

END LOOP;

-- Close the file.

UTL_FILE.fclose(l_file);

EXCEPTION

WHEN OTHERS THEN

-- Close the file if something goes wrong.

IF UTL_FILE.is_open(l_file) THEN

UTL_FILE.fclose(l_file);

END IF;

RAISE;

end write_blob;

This post has been answered by John Stegeman on Jul 6 2015
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 5 2015
Added on Jul 6 2015
18 comments
2,594 views