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!

Read binary file into BLOB (UTL_FILE.GET_RAW)

M.EmmanuelJun 20 2016 — edited Jun 20 2016

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;

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 18 2016
Added on Jun 20 2016
1 comment
4,001 views