Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi there,

I am trying to store binary[] of data into a blob column and i having some difficulty.
I have following code to allow me to store binary image data, however my current implementation is reliant on physical image existing in a directory on the server:

SQL
DECLARE
l_dir    VARCHAR2(10) := 'IMAGES';
l_file   VARCHAR2(25) := 'test.jpg';
l_bfile  BFILE;
l_blob   BLOB;

BEGIN
  INSERT INTO IMAGE_TBL (IMG_ID, IMG_DESC, IMG_DATA, IMG_EXT)
  VALUES (IMAGE_TBL_SEQ.NEXTVAL, l_file, empty_blob(), '.jpg')
  RETURN IMG_DATA INTO l_blob;

  l_bfile := BFILENAME(l_dir, l_file);
  --Opens BFILE for read-only access. BFILE data may not be written through the database.
  DBMS_LOB.fileopen(l_bfile, DBMS_LOB.file_readonly);
  DBMS_LOB.loadfromfile(l_blob,
                        l_bfile,
						DBMS_LOB.getlength(l_bfile));
  --Release the resource.						
  DBMS_LOB.fileclose(l_bfile);

  --Save the changes. This will do the actual insert of the image
  COMMIT;
END;


Now in the legacy application i'm working on, the incoming image data is base64encoded data which i then convert to binary[] array.

Can anyone please share with me the corresponding data type in Oracle that would allow me to store the binary[] data into the BLOB column?

Any code samples would be appreciated as well.

What I have tried:

I have tried the above code and researched Oracle docs but i couldn't find anything relating to storing binary data into a blob type column or storing base64encoded image to a blob type column.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900