Quantcast
Channel: Creativz Lab » pl/sql procedure
Viewing all articles
Browse latest Browse all 2

File contents into BLOB in Oracle Database, using PL/SQL

$
0
0

Often there will be a requirement for reading .out files generated by Oracle Applications and converting into pdf files and send as mail attachment.

 

Here is a sample PL/SQL procedure which can read a file from a specified location, into a BLOB and returns it.

 

The calling program can convert this blob data into any form.

 

Calling program can be another PL/SQL procedure or a Java Program or some other language program.

 

Note: following procedure works only on Oracle Database.

 

=============================================================

 

create or replace procedure READ_FILE_TO_BLOB(

dest_lob_return OUT BLOB,

file_name IN VARCHAR2)

is

  

    – BFILE_LOC is the directory created, with help of

    –create directory BFILE_LOC as ‘/export/home/test/d01/oratst/testcomn/admin/out/TEST_xxxxxxr06/’;

    src_lob  BFILE := BFILENAME(‘BFILE_LOC’, file_name); 

    dest_lob BLOB;

    v_lob_len INTEGER;

    v_offset NUMBER := 1;

    v_buffer       RAW(20);

    v_buffer_size  BINARY_INTEGER := 20;

 

BEGIN

  

   DBMS_LOB.CREATETEMPORARY(dest_lob, TRUE, DBMS_LOB.SESSION);

   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);

   dest_lob_return := dest_lob;

  

end READ_FILE_TO_BLOB;

 

===============================================================


Viewing all articles
Browse latest Browse all 2

Trending Articles