Search code examples
oracle-databaseplsql

How to insert a BLOB_FILE into DB Oracle?


How can i make an BLOB_FILE insert in PL/SQL?

My try:

 insert into MY TABLE (SOMETHING,SOMETHING,BLOB_FILE,SOMETHING,SOMETHING,SOMETHING) 
    values(1,'1234HRT',utl_raw.cast_to_raw('path\of\my\file'),7894,SYSDATE,SYSDATE);

Any tips?


Solution

  • You have many other examples of that on other posts. You need some pl/sql to send the file to the blob column: ps: you need to create a directory object to point to the folder

    DECLARE
      src_lob  BFILE := BFILENAME('MY_DIR', '/tmp/me.gif');
      dest_lob BLOB;
    BEGIN
      INSERT INTO lob_table VALUES(2, EMPTY_BLOB())
         RETURNING doc INTO dest_lob;
    
      DBMS_LOB.OPEN(src_lob, DBMS_LOB.LOB_READONLY);
      DBMS_LOB.LoadFromFile( DEST_LOB => dest_lob,
                             SRC_LOB  => src_lob,
                             AMOUNT   => DBMS_LOB.GETLENGTH(src_lob) );
      DBMS_LOB.CLOSE(src_lob);
    
      COMMIT;
    END;