title: Extract BLOB data from Oracle Database and convert to original file
body: <p>I am trying to extract <code>BLOB</code> data and convert it to the original file (pdf, rtf, doc, etc).  Below is my code:</p>
  
  <pre><code>DECLARE
    l_file      UTL_FILE.FILE_TYPE;
    l_buffer    RAW(32767);
    l_amount    BINARY_INTEGER := 32767;
    l_pos       NUMBER := 1;
    l_blob      BLOB;
    l_blob_len  NUMBER;
  BEGIN
  
    SELECT file_contents
      INTO   l_blob
      FROM   irb_files
     WHERE  FILE_NAME = 'STD_FlipBook_Religion2013.doc';
  
    l_blob_len := DBMS_LOB.getlength(l_blob);
  
    -- Open the destination file.
    l_file := UTL_FILE.fopen('IRB','STD_FlipBook_Religion2013.doc','wb','W');
  
  
    DBMS_LOB.read(l_blob, l_amount, l_pos, l_buffer);
    UTL_FILE.put_raw(l_file, l_buffer, TRUE);
    l_pos := l_pos + l_amount;
  
    -- Close the file.
    UTL_FILE.fclose(l_file);
  
  END;
  </code></pre>
  
  <p>I am relatively new to all of this so I am sorry if my code is a bit off.  The error I keep getting is:</p>
  
  <pre><code>Error report:
  ORA-06502: PL/SQL: numeric or value error: character to number conversion error
  ORA-06512: at line 18
  06502. 00000 -  "PL/SQL: numeric or value error%s"
  *Cause:    
  *Action:
  </code></pre>
  
  <p>Any help would be greatly appreciated.  </p>
  
  <p>Database Info:
  Oracle9i Enterprise Edition Release 9.2.0.5.0</p>