How to load images from oracle directory to table using BFILE ?
CREATE OR REPLACE FUNCTION base64encode (p_blob IN BLOB)RETURN CLOB-- ------------------------------------------------------------------------------------- File Name : https://oracle-base.com/dba/miscellaneous/base64encode.sql-- Author : Tim Hall-- Description : Encodes a BLOB into a Base64 CLOB.-- Last Modified: 09/11/2011-- -----------------------------------------------------------------------------------ISl_clob CLOB;l_step PLS_INTEGER := 12000; -- make sure you set a multiple of 3 not higher than 24573BEGINFOR i IN 0 .. TRUNC ( (DBMS_LOB.getlength (p_blob) - 1) / l_step)LOOPl_clob :=l_clob|| UTL_RAW.cast_to_varchar2 (UTL_ENCODE.base64_encode (DBMS_LOB.SUBSTR (p_blob, l_step, i * l_step + 1)));END LOOP;RETURN l_clob;END;
2. Store images name into a table i.e. folder_image.
3. Use below code
DECLARECURSOR r_curISSELECT filename FROM folder_image;dest_loc BLOB;dest1_loc BLOB;base_64 CLOB;src_loc BFILE;l_filename VARCHAR2 (200);BEGINFOR l_file IN r_curLOOPsrc_loc := BFILENAME ('EXAMPLE_LOB_DIR', l_file.filename);INSERT INTO test_blob (id,file_name,image,timestamp)VALUES (SYS_GUID(),l_file.filename,EMPTY_BLOB (),SYSDATE)RETURNING imageINTO dest_loc;DBMS_LOB.open (src_loc, DBMS_LOB.lob_readonly);DBMS_LOB.open (dest_loc, DBMS_LOB.lob_readwrite);DBMS_LOB.loadfromfile (dest_lob => dest_loc,src_lob => src_loc,amount => DBMS_LOB.getlength (src_loc));DBMS_LOB.close (dest_loc);DBMS_LOB.close (src_loc);l_filename := l_file.filename;SELECT imageINTO dest1_locFROM test_blobWHERE file_name = l_filename;base_64 := base64encode (dest1_loc);UPDATE test_blobSET image_base64 = base_64WHERE file_name = l_filename;END LOOP;COMMIT;END;/
No comments:
Post a Comment
Please do not add any spam links or abusive comments.