I am trying to write a procedure to read a binary file into a BLOB (v_lob) element.
I am missing something about how to handle get_raw, if someone can point me to a working example or suggest what is wrong in below's code I would strongly appreciate.
So far I have managed to get the following:
PROCEDURE read_file
IS
v_lob BLOB;
v_length NUMBER;
v_file_handle UTL_FILE.FILE_TYPE;
v_offset NUMBER := 1;
v_directory_name VARCHAR2 (500) := 'TMP_FOLDER';
v_file_name VARCHAR2 (100) := 'myBinaryFile';
BEGIN
BEGIN
v_file_handle :=
UTL_FILE.FOPEN (v_directory_name,
v_file_name,
'RB',
32767);
LOOP
UTL_FILE.GET_RAW (
v_file_handle,
DBMS_LOB.SUBSTR (v_lob, 32767, v_offset),
32767
);
v_offset := v_offset + 32767;
END LOOP;
UTL_FILE.FFLUSH (v_file_handle);
UTL_FILE.FCLOSE (v_file_handle);
EXCEPTION
WHEN no_data_found THEN
EXIT;
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE (
'Error on READ_FILE '
|| TO_CHAR (SQLCODE)
|| ' '
|| SQLERRM);
UTL_FILE.FCLOSE (v_file_handle);
RAISE;
END;
END;