Utl_compress

Dear all,
we are extracted 40 tables from oracle db by using plsql procedure and it has stored in utl directory like .txt format
now i need to extract some more tables from oracle db and first it has be compressed by using utl_compress and then store in the directory.
Can you assist me how can i do this.If you give some example its well appreciate.
Thank you in advance

Ok, so now you resort to lies to have someone other to do your work!
I googled for utl_compress and got some 9200 hits.
And you state those articles didn't provide enough information?
I bet you didn't read any of them!
Good day!
Sybrand Bakker
Senior Oracle DBA

Similar Messages

  • UTL_COMPRESS Zipping Multiple BLOBs

    Hey everyone, I'm having trouble figuring out how to use UTL_COMPRESS.
    What I want to do is take several BLOBs from one table, and put them into one zip file. Can anyone show me an example of where this is done?
    Here is some sample code of what I have so far:
    My table:
    CREATE TABLE  "FILES"
       (     "FILE_ID" NUMBER,
         "FILE_TYPE" NUMBER,
         "FILENAME" VARCHAR2(1000),
         "DATE_ADDED" DATE,
         "ADDED_BY" VARCHAR2(255),
         "FILE_BLOB" BLOB,
    /Some sample code:
    DECLARE
      b_dl_file1 BLOB;
      b_dl_file2 BLOB;
      b_dl_file3 BLOB;
      b_compressed_file BLOB;
    BEGIN
    select FILE_BLOB
    into b_dl_file1
    from FILES
    where FILE_ID = 64;
    select FILE_BLOB
    into b_dl_file2
    from FILES
    where FILE_ID = 65;
    select FILE_BLOB
    into b_dl_file3
    from FILES
    where FILE_ID = 66;
    b_compressed_file := UTL_COMPRESS.LZ_COMPRESS(b_dl_file1);
    END;So what I've posted works fine, it compresses a single file. What I want is to take all three of those blobs (for example) and add them to one zip file. I've looked into using UTL_COMPRESS.LZ_COMPRESS_ADD, but as far as I can see, that only takes RAW data. Will I have to break my BLOBs into RAW strings and then compress those? Will that even work?
    Any help would be appreciated!

    Wow! Thanks! That's exactly what I'm looking for. I'm having some trouble getting this code to run though, I'm recieving the following error:
    "ORA-06502: PL/SQL: numeric or value error: invalid LOB locator specified: ORA-22275 "
    I've been debugging and it looks like its coming from the add1file procedure.
    I modified the code a bit to make it into a package:
    CREATE OR REPLACE PACKAGE zip_blobs AS
      /*Package written by Anton Scheffer, used with permission*/
      PROCEDURE add1file(p_zipped_blob in out blob, p_name in varchar2, p_content in blob);
      PROCEDURE finish_zip(p_zipped_blob in out blob);
      PROCEDURE save_zip(p_zipped_blob in blob, p_dir in varchar2, p_filename in varchar2);
    END zip_blobs;
    CREATE OR REPLACE PACKAGE BODY zip_blobs AS
      function little_endian( p_big in number, p_bytes in pls_integer := 4 )
      return raw
      is
      begin
        return utl_raw.substr( utl_raw.cast_from_binary_integer( p_big, utl_raw.little_endian ), 1, p_bytes );
      end;
      procedure add1file
        ( p_zipped_blob in out blob
        , p_name in varchar2
        , p_content in blob
      is
        t_now date;
        t_blob blob;
        t_clen integer;
      begin
        t_now := sysdate;
        t_blob := utl_compress.lz_compress( p_content );
        t_clen := dbms_lob.getlength( t_blob );
        if p_zipped_blob is null
        then
          dbms_lob.createtemporary( p_zipped_blob, true );
        end if;
        dbms_lob.append( p_zipped_blob
                       , utl_raw.concat( hextoraw( '504B0304' ) -- Local file header signature
                                       , hextoraw( '1400' )     -- version 2.0
                                       , hextoraw( '0000' )     -- no General purpose bits
                                       , hextoraw( '0800' )     -- deflate
                                       , little_endian( to_number( to_char( t_now, 'ss' ) ) / 2
                                                      + to_number( to_char( t_now, 'mi' ) ) * 32
                                                      + to_number( to_char( t_now, 'hh24' ) ) * 2048
                                                      , 2
                                                      ) -- File last modification time
                                       , little_endian( to_number( to_char( t_now, 'dd' ) )
                                                      + to_number( to_char( t_now, 'mm' ) ) * 32
                                                      + ( to_number( to_char( t_now, 'yyyy' ) ) - 1980 ) * 512
                                                      , 2
                                                      ) -- File last modification date
                                       , dbms_lob.substr( t_blob, 4, t_clen - 7 )         -- CRC-32
                                       , little_endian( t_clen - 18 )                     -- compressed size
                                       , little_endian( dbms_lob.getlength( p_content ) ) -- uncompressed size
                                       , little_endian( length( p_name ), 2 )             -- File name length
                                       , hextoraw( '0000' )                               -- Extra field length
                                       , utl_raw.cast_to_raw( p_name )                    -- File name
        dbms_lob.append( p_zipped_blob, dbms_lob.substr( t_blob, t_clen - 18, 11 ) );     -- compressed content
        dbms_lob.freetemporary( t_blob );
      end;
      procedure finish_zip( p_zipped_blob in out blob )
      is
        t_cnt pls_integer := 0;
        t_offs integer;
        t_offs_dir_header integer;
        t_offs_end_header integer;
        t_comment raw(32767) := utl_raw.cast_to_raw( 'Implementation by Anton Scheffer' );
      begin
        t_offs_dir_header := dbms_lob.getlength( p_zipped_blob );
        t_offs := dbms_lob.instr( p_zipped_blob, hextoraw( '504B0304' ), 1 );
        while t_offs > 0
        loop
          t_cnt := t_cnt + 1;
          dbms_lob.append( p_zipped_blob
                         , utl_raw.concat( hextoraw( '504B0102' )      -- Central directory file header signature
                                         , hextoraw( '1400' )          -- version 2.0
                                         , dbms_lob.substr( p_zipped_blob, 26, t_offs + 4 )
                                         , hextoraw( '0000' )          -- File comment length
                                         , hextoraw( '0000' )          -- Disk number where file starts
                                         , hextoraw( '0100' )          -- Internal file attributes
                                         , hextoraw( '2000B681' )      -- External file attributes
                                         , little_endian( t_offs - 1 ) -- Relative offset of local file header
                                         , dbms_lob.substr( p_zipped_blob
                                                          , utl_raw.cast_to_binary_integer( dbms_lob.substr( p_zipped_blob, 2, t_offs + 26 ), utl_raw.little_endian )
                                                          , t_offs + 30
                                                          )            -- File name
          t_offs := dbms_lob.instr( p_zipped_blob, hextoraw( '504B0304' ), t_offs + 32 );
        end loop;
        t_offs_end_header := dbms_lob.getlength( p_zipped_blob );
        dbms_lob.append( p_zipped_blob
                       , utl_raw.concat( hextoraw( '504B0506' )                                    -- End of central directory signature
                                       , hextoraw( '0000' )                                        -- Number of this disk
                                       , hextoraw( '0000' )                                        -- Disk where central directory starts
                                       , little_endian( t_cnt, 2 )                                 -- Number of central directory records on this disk
                                       , little_endian( t_cnt, 2 )                                 -- Total number of central directory records
                                       , little_endian( t_offs_end_header - t_offs_dir_header )    -- Size of central directory
                                       , little_endian( t_offs_dir_header )                        -- Relative offset of local file header
                                       , little_endian( nvl( utl_raw.length( t_comment ), 0 ), 2 ) -- ZIP file comment length
                                       , t_comment
      end;
      procedure save_zip
        ( p_zipped_blob in blob
        , p_dir in varchar2
        , p_filename in varchar2
      is
        t_fh utl_file.file_type;
        t_len pls_integer := 32767;
      begin
        t_fh := utl_file.fopen( p_dir, p_filename, 'wb' );
        for i in 0 .. trunc( ( dbms_lob.getlength( p_zipped_blob ) - 1 ) / t_len )
        loop
          utl_file.put_raw( t_fh, dbms_lob.substr( p_zipped_blob, t_len, i * t_len + 1 ) );
        end loop;
        utl_file.fclose( t_fh );
      end;
    END zip_blobs;My code:
    DECLARE
      b_dl_file1 BLOB;
      b_dl_file2 BLOB;
      b_dl_file3 BLOB;
      b_zipped_blob BLOB;
    BEGIN
      select FILE_BLOB
      into b_dl_file1
      from FILES
      where FILE_ID = 64;
      select FILE_BLOB
      into b_dl_file2
      from FILES
      where FILE_ID = 65;
      select FILE_BLOB
      into b_dl_file3
      from FILES
      where FILE_ID = 66;
      zip_blobs.add1file(b_zipped_blob, 'test1.bin', b_dl_file1);
      zip_blobs.add1file(b_zipped_blob, 'test2.bin', b_dl_file2);
      zip_blobs.add1file(b_zipped_blob, 'test3.bin', b_dl_file3);
      zip_blobs.finish_zip(b_zipped_blob);
      insert into compressed_files(compressed_blob) values(b_zipped_blob);
    END;So I'm inserting it into a table, but even when I use save_zip, I get the same error. I tried playing around with freeing p_zipped_blob and not freeing t_blob, but it didn't seem to work, and I'm not seeing where else it could be going wrong. Any more help would be awesome!
    Thanks!

  • Reading UTL_COMPRESS output in Java

    I'm looking into compressing the output of a PL/SQL procedure using the UTL_COMPRESS package installed with Oracle 10g. The output will be decompressed by Java. I tried to use the java class java.util.zip.GZIPInputStream to perform the decompression, but it seems that the UTL_COMPRESS uses a different LZW algorithm than the Java class.
    Does anyone know the algorithm that UTL_COMPRESS uses? Has anyone else tried this before?

    Sorry, the documentation does not say much more, maybe you could open a service request?
    -- or -- try both to see which one works.

  • UTL_COMPRESS.LZ_COMPRESS wrong number or types of arguments in call

    Hi All -
    I've been trying to use the UTL_COMPRESS.LZ_COMPRESS in a 10gR2 (10.2.0.3) database on some interMedia objects as well as plain olf LOB objects, but keep getting these errors:
    PLS-00306: wrong number or types of arguments in call to 'LZ_COMPRESS'
    ORA-00932: inconsistent datatypes: expected NUMBER got BLOB
    For the life of me, I can't figure out what I'm doing wrong. Any insight or help would be much appreciated.
    CREATE TABLE AUDIO_TBL
    ( "AUDIO_ID" RAW(32),
    "AUDIO" "ORDSYS"."ORDAUDIO" );
    CREATE OR REPLACE PROCEDURE compress_audio1 (p_audioID IN RAW) AS
    v_src_audio ORDSYS.ORDAudio;
    v_compressed_audio blob;
    ctx RAW(64) :=NULL;
    BEGIN
    SELECT audio INTO v_src_audio FROM audio_tbl WHERE audio_id = p_audioID FOR UPDATE;
    dbms_lob.createtemporary(v_compressed_audio,true); -- make temp LOB
    obj.getContentInLob(ctx,v_compressed_audio); -- write from ORDAudio into LOB
    utl_compress.lz_compress(v_src_audio, v_compressed_audio); -- compress LOB
    UPDATE audio_tbl SET audio = v_compressed_audio WHERE audio_id = p_audioID;
    dbms_lob.freetemporary(v_compressed_audio); -- free temp LOB
    COMMIT;
    EXCEPTION
    WHEN ORDSYS.ORDSourceExceptions.METHOD_NOT_SUPPORTED THEN
    DBMS_OUTPUT.PUT_LINE('ORDSourceExceptions.METHOD_NOT_SUPPORTED caught');
    WHEN OTHERS THEN
    DBMS_OUTPUT.PUT_LINE('EXCEPTION caught');
    END;
    Warning: Procedure created with compilation errors.
    SQL> show error
    Errors for PROCEDURE COMPRESS_AUDIO1:
    LINE/COL ERROR
    8/5 PL/SQL: Statement ignored
    8/9 PLS-00302: component 'GETCONTENTINLOB' must be declared
    9/5 PL/SQL: Statement ignored
    9/5 PLS-00306: wrong number or types of arguments in call to 'LZ_COMPRESS'
    10/3 PL/SQL: SQL Statement ignored
    10/28 PL/SQL: ORA-00932: inconsistent datatypes: expected NUMBER got BLOB
    Tried to use the example in the docs here
    http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14297/ch_audref.htm#i1084527
    where it's explained how to write out an ORDAudio type to a BLOB, which seems to be necessary to use UTL_COMPRESS.
    I just can't see what I'm doing wrong here.
    RB

    I am not sure and as I am at a cutomer site I can not run a trial on their production servers ... but my suspicion is that you are trying to compress non-blob data.
    Do the following:
    desc AUDIO_TBL
    set describe depth all linenum on indent on
    desc AUDIO_TBL

  • Is UTL_COMPRESS a part of Oracle Advanced Compression?

    Hi,
    I am planning to use UTL_COMPRESS for some need to compress an file. But heard it is a part of Oracle Advanced Compression and we don't have license for that and cannot be used.
    Can any one have any idea whether it is a part of Ora Adv Compression or not?
    Thanks in advance,
    Pradeep.

    Two different things? Oracle Advanced Compression http://www.oracle.com/technology/products/database/oracle11g/pdf/advanced-compression-whitepaper.pdf
    And utl_compress - a package provides an API to allow compression and decompression of binary data (RAW, BLOB and BFILE).

  • How to ZIP file and send via SMTP in Oracle

    Dear All,
    I want to send data every month via email where the data i got from view.
    The problem is the file is to big, so i should zip it.
    the question is How i can perform it with procedure and send it automatically via Job every 1st month
    what i've done was i create a procedure to make the file in zip
    [quote/]
    CREATE OR REPLACE PROCEDURE production.CREATE_EXCEL_DTKPITerminate IS
        vvrun varchar2(3000);
        vsender varchar2(100);
        vrecepient varchar2(100);
      vccrecipient varchar2(1000);
        vsubject varchar2(1000);
        vmessage long;
        v_loc varchar2(5);
       NAME:       CREATE_EXCEL
       PURPOSE:
       REVISIONS:
       Ver        Date        Author           Description
       1.0        10/15/2012          1. Created this procedure.
       NOTES:
       Automatically available Auto Replace Keywords:
          Object Name:     CREATE_EXCEL
          Sysdate:         10/15/2012
          Date and Time:   10/15/2012, 9:42:40 , and 10/15/2012 9:42:40
          Username:         (set in TOAD Options, Procedure Editor)
          Table Name:       (set in the "New PL/SQL Object" dialog)
    begin
       vsender := '[email protected]';
         vrecepient := '[email protected]';
      vccrecipient := '[email protected]';
         vsubject := 'KPI Terminate'||TO_CHAR(SYSDATE,'MM-YYYY');
         vmessage :=
            'MESSAGE .';
         as_xlsx.query2sheet('
         select cmp_company,emp#,name,class,goucode,goudesc,job,job_name,tglkeluar
                ,nac_seq,nac_code,nac_type,nac_begin,nac_desc,reason,reason_code
                from V_KPITerminate
         --insert into blobs(blob_id,blob_name)
         --values (1,as_xlsx.finish);
         SEND_SMTP_PUZZLE_DTKRY(vsender,vrecepient,vccrecipient,vsubject,vmessage,as_xlsx.finish,'DataKPITerm -'||to_char(sysdate,'yyyy')||'.zip');
      --as_xlsx.save( 'BASE_DIR3', 'SWT.xls' );
    end;
    [/quote]
    when i execute this, Error ocured
    Message       : ORA-29278: SMTP transient error: 421 Service not available
    ORA-06512           : at "SYS.UTL_SMTP", line 21
    ORA-06512           : at "SYS.UTL_SMTP", line 97
    ORA-06512           : at "SYS.UTL_SMTP", line 399
    ORA-06512           : at "PU22PROD_123.SEND_SMTP_PUZZLE_DTKRY", line 151
    ORA-29294           : A data error occurred during compression or uncompression.
    ORA-06512           : at "PU22PROD_123.CREATE_EXCEL_KPITERM", line 60
    ORA-06512           : at line 2
    cann anyone help?
    the data is too big so i prefer it zip.. can anyone help..
    the SMTP I use is like this
    CREATE OR REPLACE PROCEDURE production.SEND_SMTP_PUZZLE_DTKRY (pSender VARCHAR2,pRecipient VARCHAR2, pCCRecipient VARCHAR2, pSubject VARCHAR2,pMessage LONG,pattach BLOB,pfilename VARCHAR2) IS
      v_src_loc  BFILE := BFILENAME('BASE_DIR3', 'pajak.xls');
          l_buffer   RAW(54);
          l_amount   BINARY_INTEGER := 54;
         l_pos      INTEGER := 1;
         l_blob     BLOB := EMPTY_BLOB;
         l_blob_len INTEGER;
          v_amount   INTEGER;
          crlf CONSTANT VARCHAR2(2):= CHR(13) || CHR(10);
      v_connection_handle  UTL_SMTP.CONNECTION;
        v_smtp_host          VARCHAR2(30) := 'mail.mayora.co.id'; --My mail server, replace it with yours.
        v_subject            VARCHAR2(30) := 'Your Test Mail';
        l_message            VARCHAR2(200) := 'This is test mail using UTL_SMTP';
      pcc varchar2(50);
      i number := 1;
      j number := 1;
      l_original_blob blob;
      l_compressed_blob blob;
    BEGIN
       BEGIN
         /*Preparing the LOB from file for attachment. */
         --DBMS_LOB.OPEN(v_src_loc, DBMS_LOB.LOB_READONLY); --Read the file
         --dBMS_LOB.CREATETEMPORARY(l_blob, TRUE); --Create temporary LOB to store the file.
         --v_amount := DBMS_LOB.GETLENGTH(v_src_loc); --Amount to store.
         --DBMS_LOB.LOADFROMFILE(l_blob, v_src_loc, v_amount); -- Loading from file into temporary LOB
         --l_blob_len := DBMS_LOB.getlength(l_blob);
      l_original_blob     := pattach;
         l_compressed_blob   := TO_BLOB('1');
      UTL_COMPRESS.lz_compress (src => l_original_blob,
                                   dst => l_compressed_blob);
      --DBMS_LOB.FREETEMPORARY(l_compressed_blob);
      l_blob := l_compressed_blob;
         l_blob_len := DBMS_LOB.getlength(l_blob);
         /*UTL_SMTP related coding. */
         v_connection_handle := UTL_SMTP.OPEN_CONNECTION(host => v_smtp_host);
         UTL_SMTP.HELO(v_connection_handle, v_smtp_host);
         UTL_SMTP.MAIL(v_connection_handle, psender);
         UTL_SMTP.RCPT(v_connection_handle, precipient);
        if pCCRecipient is not null then
            if(instr(pCCRecipient,',') = 0) then
            utl_smtp.rcpt(v_connection_handle, pCCRecipient);
            else
           while(instr(pCCRecipient,',',i) > 0)
            loop
            pcc := substr(pCCRecipient,i, instr(substr(pCCRecipient,i),',')-1);
            i := i+instr(substr(pCCRecipient,i),',');
            utl_smtp.rcpt(v_connection_handle,pcc);
            end loop;
            pcc := substr(pCCRecipient,i,length(pCCRecipient));
            utl_smtp.rcpt(v_connection_handle,pcc);
            end if;
        end if;
         --UTL_SMTP.RCPT(v_connection_handle, v_cc_email_address);
         UTL_SMTP.OPEN_DATA(v_connection_handle);
         UTL_SMTP.WRITE_DATA(v_connection_handle,
                               'FROM' || ': ' ||  psender || UTL_TCP.CRLF);
         UTL_SMTP.WRITE_DATA(v_connection_handle,
                               'TO' || ': ' ||  precipient || UTL_TCP.CRLF);
         UTL_SMTP.WRITE_DATA(v_connection_handle,
                               'CC' || ': ' ||  pCCRecipient || UTL_TCP.CRLF);
         UTL_SMTP.WRITE_DATA(v_connection_handle,
                               'SUBJECT' || ': ' ||  pSubject || UTL_TCP.CRLF);
       --MIME header.
         UTL_SMTP.WRITE_DATA(v_connection_handle,
                             'MIME-Version: 1.0' || UTL_TCP.CRLF);
        UTL_SMTP.WRITE_DATA(v_connection_handle,
                             'Content-Type: multipart/mixed; ' || UTL_TCP.CRLF);
         UTL_SMTP.WRITE_DATA(v_connection_handle,
                             ' boundary= "' || 'BASE_DIR3.SECBOUND' || '"' ||
                             UTL_TCP.CRLF);
         UTL_SMTP.WRITE_DATA(v_connection_handle, UTL_TCP.CRLF);
         -- Mail Body
         UTL_SMTP.WRITE_DATA(v_connection_handle,
                             '--' || 'BASE_DIR3.SECBOUND' || UTL_TCP.CRLF);
         UTL_SMTP.WRITE_DATA(v_connection_handle,
                             'Content-Type: text/plain;' || UTL_TCP.CRLF);
         UTL_SMTP.WRITE_DATA(v_connection_handle,
                             ' charset=US-ASCII' || UTL_TCP.CRLF);
         UTL_SMTP.WRITE_DATA(v_connection_handle, UTL_TCP.CRLF);
         UTL_SMTP.WRITE_DATA(v_connection_handle, Pmessage || UTL_TCP.CRLF);
         UTL_SMTP.WRITE_DATA(v_connection_handle, UTL_TCP.CRLF);
         -- Mail Attachment
       UTL_SMTP.WRITE_DATA(v_connection_handle,
                             '--' || 'BASE_DIR3.SECBOUND' || UTL_TCP.CRLF);
        UTL_SMTP.WRITE_DATA(v_connection_handle,
                             'Content-Type: application/octet-stream' ||
                             UTL_TCP.CRLF);
         UTL_SMTP.WRITE_DATA(v_connection_handle,
                             'Content-Disposition: attachment; ' || UTL_TCP.CRLF);
         UTL_SMTP.WRITE_DATA(v_connection_handle,
                             ' filename="' || pfilename || '"' || --My filename
                             UTL_TCP.CRLF);
         UTL_SMTP.WRITE_DATA(v_connection_handle,
                             'Content-Transfer-Encoding: base64' || UTL_TCP.CRLF);
         UTL_SMTP.WRITE_DATA(v_connection_handle, UTL_TCP.CRLF);
       /* Writing the BLOL in chunks */
         WHILE l_pos < l_blob_len LOOP
           DBMS_LOB.READ(l_blob, l_amount, l_pos, l_buffer);
           UTL_SMTP.write_raw_data(v_connection_handle,
                                  UTL_ENCODE.BASE64_ENCODE(l_buffer));
           UTL_SMTP.WRITE_DATA(v_connection_handle, UTL_TCP.CRLF);
           l_buffer := NULL;
           l_pos    := l_pos + l_amount;
        END LOOP;
         UTL_SMTP.WRITE_DATA(v_connection_handle, UTL_TCP.CRLF);
         -- Close Email
         UTL_SMTP.WRITE_DATA(v_connection_handle,
                             '--' || 'BASE_DIR3.SECBOUND' || '--' || UTL_TCP.CRLF);
         UTL_SMTP.WRITE_DATA(v_connection_handle,
                             UTL_TCP.CRLF || '.' || UTL_TCP.CRLF);
         UTL_SMTP.CLOSE_DATA(v_connection_handle);
         UTL_SMTP.QUIT(v_connection_handle);
      EXCEPTION
        WHEN OTHERS THEN NULL;
        --return 1;
          UTL_SMTP.QUIT(v_connection_handle);
          RAISE;
      END;
    END;

    this is my smtp procedure
    CREATE OR REPLACE PROCEDURE PROD.SEND_SMTP_PUZZLE_DTKRY (pSender VARCHAR2,pRecipient VARCHAR2, pCCRecipient VARCHAR2, pSubject VARCHAR2,pMessage LONG,pattach BLOB,pfilename VARCHAR2) IS
      v_src_loc  BFILE := BFILENAME('BASE_DIR3', 'pajak.xls');
          l_buffer   RAW(54);
          l_amount   BINARY_INTEGER := 54;
         l_pos      INTEGER := 1;
         l_blob     BLOB := EMPTY_BLOB;
         l_blob_len INTEGER;
          v_amount   INTEGER;
          crlf CONSTANT VARCHAR2(2):= CHR(13) || CHR(10);
      v_connection_handle  UTL_SMTP.CONNECTION;
        v_smtp_host          VARCHAR2(30) := 'mail.mayora.co.id'; --My mail server, replace it with yours.
        v_subject            VARCHAR2(30) := 'Your Test Mail';
        l_message            VARCHAR2(200) := 'This is test mail using UTL_SMTP';
      pcc varchar2(50);
      i number := 1;
      j number := 1;
      l_original_blob blob;
      l_compressed_blob blob;
    BEGIN
       BEGIN
         /*Preparing the LOB from file for attachment. */
         --DBMS_LOB.OPEN(v_src_loc, DBMS_LOB.LOB_READONLY); --Read the file
         --dBMS_LOB.CREATETEMPORARY(l_blob, TRUE); --Create temporary LOB to store the file.
         --v_amount := DBMS_LOB.GETLENGTH(v_src_loc); --Amount to store.
         --DBMS_LOB.LOADFROMFILE(l_blob, v_src_loc, v_amount); -- Loading from file into temporary LOB
         --l_blob_len := DBMS_LOB.getlength(l_blob);
      l_original_blob     := pattach;
         l_compressed_blob   := TO_BLOB('1');
      UTL_COMPRESS.lz_compress (src => l_original_blob,
                                   dst => l_compressed_blob);
      --DBMS_LOB.FREETEMPORARY(l_compressed_blob);
      l_blob := l_compressed_blob;
         l_blob_len := DBMS_LOB.getlength(l_blob);
         /*UTL_SMTP related coding. */
         v_connection_handle := UTL_SMTP.OPEN_CONNECTION(host => v_smtp_host);
         UTL_SMTP.HELO(v_connection_handle, v_smtp_host);
         UTL_SMTP.MAIL(v_connection_handle, psender);
         UTL_SMTP.RCPT(v_connection_handle, precipient);
        if pCCRecipient is not null then
            if(instr(pCCRecipient,',') = 0) then
            utl_smtp.rcpt(v_connection_handle, pCCRecipient);
            else
            while(instr(pCCRecipient,',',i) > 0)
            loop
            pcc := substr(pCCRecipient,i, instr(substr(pCCRecipient,i),',')-1);
            i := i+instr(substr(pCCRecipient,i),',');
            utl_smtp.rcpt(v_connection_handle,pcc);
            end loop;
            pcc := substr(pCCRecipient,i,length(pCCRecipient));
            utl_smtp.rcpt(v_connection_handle,pcc);
            end if;
        end if;
         --UTL_SMTP.RCPT(v_connection_handle, v_cc_email_address);
         UTL_SMTP.OPEN_DATA(v_connection_handle);
         UTL_SMTP.WRITE_DATA(v_connection_handle,
                               'FROM' || ': ' ||  psender || UTL_TCP.CRLF);
         UTL_SMTP.WRITE_DATA(v_connection_handle,
                               'TO' || ': ' ||  precipient || UTL_TCP.CRLF);
         UTL_SMTP.WRITE_DATA(v_connection_handle,
                               'CC' || ': ' ||  pCCRecipient || UTL_TCP.CRLF);
         UTL_SMTP.WRITE_DATA(v_connection_handle,
                               'SUBJECT' || ': ' ||  pSubject || UTL_TCP.CRLF);
         --MIME header.
         UTL_SMTP.WRITE_DATA(v_connection_handle,
                             'MIME-Version: 1.0' || UTL_TCP.CRLF);
        UTL_SMTP.WRITE_DATA(v_connection_handle,
                             'Content-Type: multipart/mixed; ' || UTL_TCP.CRLF);
         UTL_SMTP.WRITE_DATA(v_connection_handle,
                             ' boundary= "' || 'BASE_DIR3.SECBOUND' || '"' ||
                             UTL_TCP.CRLF);
         UTL_SMTP.WRITE_DATA(v_connection_handle, UTL_TCP.CRLF);
         -- Mail Body
         UTL_SMTP.WRITE_DATA(v_connection_handle,
                             '--' || 'BASE_DIR3.SECBOUND' || UTL_TCP.CRLF);
         UTL_SMTP.WRITE_DATA(v_connection_handle,
                             'Content-Type: text/plain;' || UTL_TCP.CRLF);
         UTL_SMTP.WRITE_DATA(v_connection_handle,
                             ' charset=US-ASCII' || UTL_TCP.CRLF);
         UTL_SMTP.WRITE_DATA(v_connection_handle, UTL_TCP.CRLF);
         UTL_SMTP.WRITE_DATA(v_connection_handle, Pmessage || UTL_TCP.CRLF);
         UTL_SMTP.WRITE_DATA(v_connection_handle, UTL_TCP.CRLF);
         -- Mail Attachment
       UTL_SMTP.WRITE_DATA(v_connection_handle,
                             '--' || 'BASE_DIR3.SECBOUND' || UTL_TCP.CRLF);
        UTL_SMTP.WRITE_DATA(v_connection_handle,
                             'Content-Type: application/octet-stream' ||
                             UTL_TCP.CRLF);
         UTL_SMTP.WRITE_DATA(v_connection_handle,
                             'Content-Disposition: attachment; ' || UTL_TCP.CRLF);
         UTL_SMTP.WRITE_DATA(v_connection_handle,
                             ' filename="' || pfilename || '"' || --My filename
                             UTL_TCP.CRLF);
         UTL_SMTP.WRITE_DATA(v_connection_handle,
                             'Content-Transfer-Encoding: base64' || UTL_TCP.CRLF);
         UTL_SMTP.WRITE_DATA(v_connection_handle, UTL_TCP.CRLF);
       /* Writing the BLOL in chunks */
         WHILE l_pos < l_blob_len LOOP
           DBMS_LOB.READ(l_blob, l_amount, l_pos, l_buffer);
           UTL_SMTP.write_raw_data(v_connection_handle,
                                  UTL_ENCODE.BASE64_ENCODE(l_buffer));
           UTL_SMTP.WRITE_DATA(v_connection_handle, UTL_TCP.CRLF);
           l_buffer := NULL;
           l_pos    := l_pos + l_amount;
        END LOOP;
         UTL_SMTP.WRITE_DATA(v_connection_handle, UTL_TCP.CRLF);
         -- Close Email
         UTL_SMTP.WRITE_DATA(v_connection_handle,
                             '--' || 'BASE_DIR3.SECBOUND' || '--' || UTL_TCP.CRLF);
         UTL_SMTP.WRITE_DATA(v_connection_handle,
                             UTL_TCP.CRLF || '.' || UTL_TCP.CRLF);
         UTL_SMTP.CLOSE_DATA(v_connection_handle);
         UTL_SMTP.QUIT(v_connection_handle);
      EXCEPTION
        WHEN OTHERS THEN NULL;
        --return 1;
          UTL_SMTP.QUIT(v_connection_handle);
          RAISE;
      END;
    END;
    is there a mistake?

  • Storing PDF and Word document in oracle database

    any idea, how to store PDF and word document using oracle database.
    thanks

    The common approach is store as BLOB in database, use DBMS_LOB package to handle the loading and reading, sample script source asktom
    Also check this thread in Asktom
    SQL> create table demo
      2  ( id        INT PRIMARY KEY,
      3    theBlob   blob,
      4    dummy_col VARCHAR2(1)
      5  )
      6  /
    Table created.
    SQL> -- --------------------------------------------------------------
    SQL> -- Load a PDF file into a BLOB field and compress the BLOB.
    SQL> -- --------------------------------------------------------------
    SQL> declare
      2      l_blob    blob;
      3      l_bfile   bfile;
      4 
      5  begin
      6      insert into demo (id, theBLOB) values ( 1, empty_blob() )
      7      returning theBlob into l_blob;
      8 
      9      l_bfile := bfilename( 'BLOB_DIR', 'Test.PDF' );
    10      dbms_lob.fileopen( l_bfile );
    11 
    12      dbms_lob.loadfromfile( l_blob,
    13                             l_bfile,
    14                             dbms_lob.getlength( l_bfile ) );
    15 
    16      UPDATE demo
    17      SET    theBlob = utl_compress.lz_compress(l_blob, 6)
    18      WHERE  id = 1;
    19  -- If you don't want compress the LOB just update directly
    20      dbms_lob.fileclose( l_bfile );
    21      COMMIT;
    22  end;
    23  /
    PL/SQL procedure successfully completed

  • Unzip data received from web service?

    In my Apex 3.0.1 application I am trying to obtain data from a web service. The problem is that the returned data is first zipped and then encoded using base 64 coding.
    I can decode the data using the utl_encode package and if I download the result, I can unzip it using winzip to get the original XML message. However, I need to unzip the message within Apex in order to process the content. The Oracle package utl_compress provides uncompression functions for the LZ compression algorithm but this does not seem to be the same as winzip etc.
    Thanks for any suggestions anyone might have.

    One way would be to use a Java stored procedure to perform the unzipping.

  • Unzip a folder using pl/sql

    Hi All,
    I am creating zip folder using oracle pl/sql. Now i want to unzip the same folder for taking out the compressed file.
    Is it possible to unzip the folder in oracle pl/sql.
    Thanks in Advance.
    Cheers,
    Shan

    Here's the code
    Anton
    CREATE OR REPLACE package as_zip
    is
      type file_list is table of clob;
      function get_file_list(
        p_dir in varchar2
      , p_zip_file in varchar2
      , p_encoding in varchar2 := null
        return file_list;
      function get_file_list(
        p_zipped_blob in blob
      , p_encoding in varchar2 := null /* Use CP850 for zip files created with a German Winzip to see umlauts, etc */
        return file_list;
      function get_file(
        p_dir in varchar2
      , p_zip_file in varchar2
      , p_file_name in varchar2
      , p_encoding in varchar2 := null
        return blob;
      function get_file(
        p_zipped_blob in blob
      , p_file_name in varchar2
      , p_encoding in varchar2 := null
        return blob;
      procedure add1file(
        p_zipped_blob in out blob
      , p_name in varchar2
      , p_content in blob
      procedure finish_zip(
        p_zipped_blob in out blob
      procedure save_zip(
        p_zipped_blob in blob
      , p_dir in varchar2 := 'MY_DIR'
      , p_filename in varchar2 := 'my.zip'
    declare
      g_zipped_blob blob;
    begin
      as_zip.add1file( g_zipped_blob, 'test1.txt', utl_raw.cast_to_raw( 'Dit is de laatste test! Waarom wordt dit dan niet gecomprimeerd?' ) );
      as_zip.add1file( g_zipped_blob, 'test1234.txt', utl_raw.cast_to_raw( 'En hier staat wat anders' ) );
      as_zip.finish_zip( g_zipped_blob );
      as_zip.save_zip( g_zipped_blob, 'MY_DIR', 'my.zip' );
    end;
    declare
      t_dir varchar2(100) := 'MY_DIR';
      t_zip varchar2(100) := 'my.zip';
      zip_files as_zip.file_list;
    begin
      zip_files  := as_zip.get_file_list( t_dir, t_zip );
      for i in zip_files.first() .. zip_files.last
      loop
        dbms_output.put_line( zip_files( i ) );
        dbms_output.put_line( utl_raw.cast_to_varchar2( as_zip.get_file( t_dir, t_zip, zip_files( i ) ) ) );
      end loop;
    end;
    end;
    CREATE OR REPLACE package body as_zip
    is
      function raw2num(
        p_value in raw
        return number
      is
      begin                                               -- note: FFFFFFFF => -1
        return utl_raw.cast_to_binary_integer( p_value
                                             , utl_raw.little_endian
      end;
      function file2blob(
        p_dir in varchar2
      , p_file_name in varchar2
        return blob
      is
        file_lob bfile;
        file_blob blob;
      begin
        file_lob := bfilename( p_dir
                             , p_file_name
        dbms_lob.open( file_lob
                     , dbms_lob.file_readonly
        dbms_lob.createtemporary( file_blob
                                , true
        dbms_lob.loadfromfile( file_blob
                             , file_lob
                             , dbms_lob.lobmaxsize
        dbms_lob.close( file_lob );
        return file_blob;
      exception
        when others
        then
          if dbms_lob.isopen( file_lob ) = 1
          then
            dbms_lob.close( file_lob );
          end if;
          if dbms_lob.istemporary( file_blob ) = 1
          then
            dbms_lob.freetemporary( file_blob );
          end if;
          raise;
      end;
      function raw2varchar2(
        p_raw in raw
      , p_encoding in varchar2
        return varchar2
      is
      begin
        return nvl
                ( utl_i18n.raw_to_char( p_raw
                                      , p_encoding
                , utl_i18n.raw_to_char
                                ( p_raw
                                , utl_i18n.map_charset( p_encoding
                                                      , utl_i18n.generic_context
                                                      , utl_i18n.iana_to_oracle
      end;
      function get_file_list(
        p_dir in varchar2
      , p_zip_file in varchar2
      , p_encoding in varchar2 := null
        return file_list
      is
      begin
        return get_file_list( file2blob( p_dir
                                       , p_zip_file
                            , p_encoding
      end;
      function get_file_list(
        p_zipped_blob in blob
      , p_encoding in varchar2 := null
        return file_list
      is
        t_ind integer;
        t_hd_ind integer;
        t_rv file_list;
      begin
        t_ind := dbms_lob.getlength( p_zipped_blob ) - 21;
        loop
          exit when dbms_lob.substr( p_zipped_blob
                                   , 4
                                   , t_ind
                                   ) = hextoraw( '504B0506' )
                or t_ind < 1;
          t_ind := t_ind - 1;
        end loop;
        if t_ind <= 0
        then
          return null;
        end if;
        t_hd_ind := raw2num( dbms_lob.substr( p_zipped_blob
                                            , 4
                                            , t_ind + 16
                                            ) ) + 1;
        t_rv := file_list( );
        t_rv.extend( raw2num( dbms_lob.substr( p_zipped_blob
                                             , 2
                                             , t_ind + 10
        for i in 1 .. raw2num( dbms_lob.substr( p_zipped_blob
                                              , 2
                                              , t_ind + 8
        loop
          t_rv( i ) :=
            raw2varchar2
                 ( dbms_lob.substr( p_zipped_blob
                                  , raw2num( dbms_lob.substr( p_zipped_blob
                                                            , 2
                                                            , t_hd_ind + 28
                                  , t_hd_ind + 46
                 , p_encoding
          t_hd_ind :=
              t_hd_ind
            + 46
            + raw2num( dbms_lob.substr( p_zipped_blob
                                      , 2
                                      , t_hd_ind + 28
            + raw2num( dbms_lob.substr( p_zipped_blob
                                      , 2
                                      , t_hd_ind + 30
            + raw2num( dbms_lob.substr( p_zipped_blob
                                      , 2
                                      , t_hd_ind + 32
        end loop;
        return t_rv;
      end;
      function get_file(
        p_dir in varchar2
      , p_zip_file in varchar2
      , p_file_name in varchar2
      , p_encoding in varchar2 := null
        return blob
      is
      begin
        return get_file( file2blob( p_dir
                                  , p_zip_file
                       , p_file_name
                       , p_encoding
      end;
      function get_file(
        p_zipped_blob in blob
      , p_file_name in varchar2
      , p_encoding in varchar2 := null
        return blob
      is
        t_tmp blob;
        t_ind integer;
        t_hd_ind integer;
        t_fl_ind integer;
      begin
        t_ind := dbms_lob.getlength( p_zipped_blob ) - 21;
        loop
          exit when dbms_lob.substr( p_zipped_blob
                                   , 4
                                   , t_ind
                                   ) = hextoraw( '504B0506' )
                or t_ind < 1;
          t_ind := t_ind - 1;
        end loop;
        if t_ind <= 0
        then
          return null;
        end if;
        t_hd_ind := raw2num( dbms_lob.substr( p_zipped_blob
                                            , 4
                                            , t_ind + 16
                                            ) ) + 1;
        for i in 1 .. raw2num( dbms_lob.substr( p_zipped_blob
                                              , 2
                                              , t_ind + 8
        loop
          if p_file_name =
               raw2varchar2
                 ( dbms_lob.substr( p_zipped_blob
                                  , raw2num( dbms_lob.substr( p_zipped_blob
                                                            , 2
                                                            , t_hd_ind + 28
                                  , t_hd_ind + 46
                 , p_encoding
          then
            if dbms_lob.substr( p_zipped_blob
                              , 2
                              , t_hd_ind + 10
                              ) = hextoraw( '0800' )                -- deflate
            then
              t_fl_ind :=
                    raw2num( dbms_lob.substr( p_zipped_blob
                                            , 4
                                            , t_hd_ind + 42
              t_tmp := hextoraw( '1F8B0800000000000003' );          -- gzip header
              dbms_lob.copy( t_tmp
                           , p_zipped_blob
                           , raw2num( dbms_lob.substr( p_zipped_blob
                                                     , 4
                                                     , t_fl_ind + 19
                           , 11
                           ,   t_fl_ind
                             + 31
                             + raw2num( dbms_lob.substr( p_zipped_blob
                                                       , 2
                                                       , t_fl_ind + 27
                             + raw2num( dbms_lob.substr( p_zipped_blob
                                                       , 2
                                                       , t_fl_ind + 29
              dbms_lob.append( t_tmp
                             , dbms_lob.substr( p_zipped_blob
                                              , 4
                                              , t_fl_ind + 15
              dbms_lob.append( t_tmp
                             , dbms_lob.substr( p_zipped_blob, 4, t_fl_ind + 23 )
              return utl_compress.lz_uncompress( t_tmp );
            end if;
            if dbms_lob.substr( p_zipped_blob
                              , 2
                              , t_hd_ind + 10
                              ) =
                          hextoraw( '0000' )
                                            -- The file is stored (no compression)
            then
              t_fl_ind :=
                    raw2num( dbms_lob.substr( p_zipped_blob
                                            , 4
                                            , t_hd_ind + 42
              return dbms_lob.substr( p_zipped_blob
                                    , raw2num( dbms_lob.substr( p_zipped_blob
                                                              , 4
                                                              , t_fl_ind + 19
                                    ,   t_fl_ind
                                      + 31
                                      + raw2num( dbms_lob.substr( p_zipped_blob
                                                                , 2
                                                                , t_fl_ind + 27
                                      + raw2num( dbms_lob.substr( p_zipped_blob
                                                                , 2
                                                                , t_fl_ind + 29
            end if;
          end if;
          t_hd_ind :=
              t_hd_ind
            + 46
            + raw2num( dbms_lob.substr( p_zipped_blob
                                      , 2
                                      , t_hd_ind + 28
            + raw2num( dbms_lob.substr( p_zipped_blob
                                      , 2
                                      , t_hd_ind + 30
            + raw2num( dbms_lob.substr( p_zipped_blob
                                      , 2
                                      , t_hd_ind + 32
        end loop;
        return null;
      end;
      function little_endian(
        p_big in number
      , p_bytes in pls_integer := 4
        return raw
      is
      begin
        return utl_raw.substr
                      ( utl_raw.cast_from_binary_integer( p_big
                                                        , utl_raw.little_endian
                      , 1
                      , p_bytes
      end;
      procedure add1file(
        p_zipped_blob in out blob
      , p_name in varchar2
      , p_content in blob
      is
        t_now date;
        t_blob blob;
        t_clen integer;
      begin
        t_now := sysdate;
        t_blob := utl_compress.lz_compress( p_content );
        t_clen := dbms_lob.getlength( t_blob );
        if p_zipped_blob is null
        then
          dbms_lob.createtemporary( p_zipped_blob
                                  , true
        end if;
        dbms_lob.append
          ( p_zipped_blob
          , utl_raw.concat
              ( hextoraw( '504B0304' )              -- Local file header signature
              , hextoraw( '1400' )                  -- version 2.0
              , hextoraw( '0000' )                  -- no General purpose bits
              , hextoraw( '0800' )                  -- deflate
              , little_endian
                  (   to_number( to_char( t_now
                                        , 'ss'
                                        ) ) / 2
                    + to_number( to_char( t_now
                                        , 'mi'
                                        ) ) * 32
                    + to_number( to_char( t_now
                                        , 'hh24'
                                        ) ) * 2048
                  , 2
                  )                                 -- File last modification time
              , little_endian
                  (   to_number( to_char( t_now
                                        , 'dd'
                    + to_number( to_char( t_now
                                        , 'mm'
                                        ) ) * 32
                    + ( to_number( to_char( t_now
                                          , 'yyyy'
                                          ) ) - 1980 ) * 512
                  , 2
                  )                                 -- File last modification date
              , dbms_lob.substr( t_blob
                               , 4
                               , t_clen - 7
                               )                                         -- CRC-32
              , little_endian( t_clen - 18 )                    -- compressed size
              , little_endian( dbms_lob.getlength( p_content ) )
                                                              -- uncompressed size
              , little_endian( length( p_name )
                             , 2
                             )                                 -- File name length
              , hextoraw( '0000' )                           -- Extra field length
              , utl_raw.cast_to_raw( p_name )                         -- File name
        dbms_lob.copy( p_zipped_blob
                     , t_blob
                     , t_clen - 18
                     , dbms_lob.getlength( p_zipped_blob ) + 1
                     , 11
                     );                                      -- compressed content
        dbms_lob.freetemporary( t_blob );
      end;
      procedure finish_zip(
        p_zipped_blob in out blob
      is
        t_cnt pls_integer := 0;
        t_offs integer;
        t_offs_dir_header integer;
        t_offs_end_header integer;
        t_comment raw( 32767 )
                     := utl_raw.cast_to_raw( 'Implementation by Anton Scheffer' );
      begin
        t_offs_dir_header := dbms_lob.getlength( p_zipped_blob );
        t_offs := dbms_lob.instr( p_zipped_blob
                                , hextoraw( '504B0304' )
                                , 1
        while t_offs > 0
        loop
          t_cnt := t_cnt + 1;
          dbms_lob.append
            ( p_zipped_blob
            , utl_raw.concat
                ( hextoraw( '504B0102' )
                                        -- Central directory file header signature
                , hextoraw( '1400' )                                -- version 2.0
                , dbms_lob.substr( p_zipped_blob
                                 , 26
                                 , t_offs + 4
                , hextoraw( '0000' )                        -- File comment length
                , hextoraw( '0000' )              -- Disk number where file starts
                , hextoraw( '0100' )                   -- Internal file attributes
                , hextoraw( '2000B681' )               -- External file attributes
                , little_endian( t_offs - 1 )
                                           -- Relative offset of local file header
                , dbms_lob.substr
                    ( p_zipped_blob
                    , utl_raw.cast_to_binary_integer
                                               ( dbms_lob.substr( p_zipped_blob
                                                                , 2
                                                                , t_offs + 26
                                               , utl_raw.little_endian
                    , t_offs + 30
                    )                                                 -- File name
          t_offs :=
              dbms_lob.instr( p_zipped_blob
                            , hextoraw( '504B0304' )
                            , t_offs + 32
        end loop;
        t_offs_end_header := dbms_lob.getlength( p_zipped_blob );
        dbms_lob.append
          ( p_zipped_blob
          , utl_raw.concat
              ( hextoraw( '504B0506' )       -- End of central directory signature
              , hextoraw( '0000' )                          -- Number of this disk
              , hextoraw( '0000' )          -- Disk where central directory starts
              , little_endian
                       ( t_cnt
                       , 2
                       )       -- Number of central directory records on this disk
              , little_endian( t_cnt
                             , 2
                             )        -- Total number of central directory records
              , little_endian( t_offs_end_header - t_offs_dir_header )
                                                      -- Size of central directory
              , little_endian
                        ( t_offs_dir_header )
                                           -- Relative offset of local file header
              , little_endian
                    ( nvl( utl_raw.length( t_comment )
                         , 0
                    , 2
                    )                                   -- ZIP file comment length
              , t_comment
      end;
      procedure save_zip(
        p_zipped_blob in blob
      , p_dir in varchar2 := 'MY_DIR'
      , p_filename in varchar2 := 'my.zip'
      is
        t_fh utl_file.file_type;
        t_len pls_integer := 32767;
      begin
        t_fh := utl_file.fopen( p_dir
                              , p_filename
                              , 'wb'
        for i in 0 .. trunc(  ( dbms_lob.getlength( p_zipped_blob ) - 1 ) / t_len )
        loop
          utl_file.put_raw( t_fh
                          , dbms_lob.substr( p_zipped_blob
                                           , t_len
                                           , i * t_len + 1
        end loop;
        utl_file.fclose( t_fh );
      end;
    end;
    /

  • Upload and ZIP a file (BLOB)

    Hi
    I am trying to upload a file and zip it before saving it to the table. I am using 3.2 and 11g. I know of UTL_COMPRESS but that's not the format I am looking for. I am looking for a .zip file . I also tried this solution (http://joelkallman.blogspot.com/2008/04/zip-it.html) but it is not working for me. when I run this process it takes a long time and finally is throwing a not responding error. I dont't know if it is the oracle 11g version that is causing this solution not to work. Please advice.
    This is the code I am running based on the above java proc in the link
    DECLARE
    l_blob BLOB;
    l_result INTEGER;
    n_field NUMBER;
    BEGIN
    SELECT MAX (id)
    INTO n_field
    FROM apex_application_files
    WHERE name = attachment_name;
    l_result := ESCRMGR.ziplobs ('SELECT id, blob_content FROM apex_application_files'||
    'WHERE id = n_feild',
    l_blob);

    Are you running add1file, and then finish_zip before inserting?I am doing this.
    Also, make sure you change the dbms_lob.append line in add1file to dbms_lob.copy (2nd last post in that other thread)I have made these changes teh very frist time I executed the procs.
    Does the PDF open after you download it from your table?Yes, I am able to open the PDF.
    But, as you mentioned mimetype may be the problem. While I am storing the file into my table, I am loading the output file from finish_zip, but I am storing the mimetype from the apex_application_files table. So, i am stroing PDF as my mime type. Then fro download I am using the followwing proc
    CREATE OR REPLACE PROCEDURE ESCRMGR.download_my_file(p_file in number) AS
    v_mime VARCHAR2(48);
    v_length NUMBER;
    v_file_name VARCHAR2(2000);
    Lob_loc BLOB;
    BEGIN
    SELECT attachment_type, attachment,attachment_name ,DBMS_LOB.GETLENGTH(attachment)
    INTO v_mime,lob_loc,v_file_name,v_length
    FROM rs_attachments
    WHERE attachment_id = p_file;
    -- set up HTTP header
    -- use an NVL around the mime type and
    -- if it is a null set it to application/octect
    -- application/octect may launch a download window from windows
    owa_util.mime_header( nvl(v_mime,'application/octet'), FALSE );
    -- set the size so the browser knows how much to download
    htp.p('Content-length: ' || v_length);
    -- the filename will be used by the browser if the users does a save as
    htp.p('Content-Disposition: attachment; filename="'||replace(replace(substr(v_file_name,instr(v_file_name,'/')+1),chr(10),null),chr(13),null)|| '"');
    -- close the headers
    owa_util.http_header_close;
    -- download the BLOB
    wpg_docload.download_file( Lob_loc );
    end download_my_file;
    So, from the above proc I understand that it is taking PDF as the mimetype and that is why it is not displaying as .ZIP
    correct me if I am wrong. I will try to work on this. But please let me know your inputs.

  • How to read a Zip file in PL/SQL program

    Hi,
    I was Reading a ".csv" file from a web URL eg. "www.aba.com/zxc.csv" in my PL/SQL procedure using UTL_HTTP package and loading data in my DB.
    Now that file is in .zip format, is there any way that I can still read that .csv.zip file through my PL/SQL procedure. Because now I have to download it first then
    unzip it and then I am loading it into my DB using UTL_FILE package instead I want to do it automatically as I was doing it before when it was not zipped.
    Thanks & Regards
    Sanjay

    Peters solution is a great, nice alternative - you should consider it.
    But your present solution reads the data from the web using UTL_HTTP into a CLOB I presume? So you are not hitting the file system at all?
    If it is not an option for you to go to the file system, then it is possible that you can use [url http://docs.oracle.com/cd/E11882_01/appdev.112/e25788/u_compr.htm#BGBBCDDI]UTL_COMPRESS package.
    That is (maybe) a possibility if the zip file only contains one file - it cannot handle if the zip file is a zip archive with several files in it.
    You could try doing your UTL_HTTP load into a BLOB and then call UTL_COMPRESS.LZ_UNCOMPRESS to unzip that BLOB into another BLOB.
    I'm not guaranteeing it will work, but it may be worth a try if you cannot do it Peters way ;-)

  • Viewing a BLOB Data (Including Compressed Data) in Classic Report APEX 3.2

    Hi All,
    I have a table with a BLOB field.
    That blob field is containing image with .tiff format.
    I need to display those images in APEX 3.2 Classic Report.
    Am able to achieve this by following the instructions in the below link.
    http://st-curriculum.oracle.com/obe/db/apex/r31/apex31nf/apex31blob.htm#t4
    Now my problem is, Some of the image in my table is in compressed format.
    So those images are not displaying in the report, rather it is giving a message called 'No Preview Available'.
    How can i extract those images and display in the Classic Report.
    Please help me to achieve this.
    Thanks & Regards,
    Sakthi.

    What kind of compression are we talking about here ?
    <li>If its some kind of native image compression methods, then you could try the ORDImage utlity, here's a thread which discusses that : {thread:id=1048248}
    If its compressed using zip or some file compression utility, you may need to load the java code(into the DB) that can uncompress it for you and then call it from procedure which then uncompress'es it(using java class) and then send it back as an image(programmatic way way of showing images in apex).
    There posts should be of assistance
    <li>Extract XML from docx . Forget the post title , this post has some code which uncompresses a zip file in the database(ignore the rest of the post, if irrelevant).
    <li>Another posting about the same requirement, but with code for unzipping which you can adapt
    <li>If you are not in a hurry, this Oracle-Sun Java documentation explains the whole process of compression/uncompression with code that you can process within the database(from PLSQL using java wrapper)
    <li>The simplest is the PLSQL Package UTL_COMPRESS utility (also ) , which wouldn't need any extra coding for compressing/uncompressing binary data.this<a/>) , which wouldn't need any extra coding for compressing/uncompressing binary data.

  • Compress PDF

    Hi Experts,
    We have loaded very large PDF files which has images in it to our production oracle database, but where in which we supposed to upload only 8MB files. when the files goes beyond 8MB we suppose to compress using adobe professional and them load it.
    Now, We are in the position to compress the loaded files(nearly 1800 fiels) is in database.
    We tried to compress with oracle utility called UTL_COMPRESS, it was not worked effectively, moreover it uses its own compression algorith and hence Adobe unable to read the compressed files.
    is there any way to archive the PDF (CLOB) which is in oracle database.
    Cheers,
    Salai

    Acrobat is not technically suited nor licensed for server use.
    Adobe's PDF Library might offer methods to compress,I think it has an API to the PDF optimizer.

  • Sending PDF as attachment using utl_smtp

    Hi all,
    I am encountering the following problem when i try to send the email using utl_smtp builtin,i receive the mail in my outlook,but not able to read the contents of the pdf file.
    Oracle Version :- Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Prod
    source code:-
    CREATE OR REPLACE PROCEDURE "PROC_MAIL_ATTACH_PDFS" (
    p_cust_nb IN cstm.cstm_cust_nb%TYPE,
    from_name IN VARCHAR2,
    to_name IN VARCHAR2,
    subject IN VARCHAR2,
    MESSAGE IN VARCHAR2,
    p_binary_file IN VARCHAR2,
    p_seq_id IN NUMBER,
    p_ret_cd OUT NUMBER,
    p_ret_desc OUT VARCHAR2
    --ISO-8859-6
    IS
    v_smtp_server VARCHAR2 (100) := '172.20.204.17';
    --change this to your mail server
    v_smtp_server_port NUMBER := 25;
    v_directory_name VARCHAR2 (100);
    v_file_name VARCHAR2 (100);
    v_line VARCHAR2 (1000);
    crlf VARCHAR2 (2) := CHR (13)
    || CHR (10);
    mesg VARCHAR2 (32767);
    conn UTL_SMTP.connection;
    v_slash_pos NUMBER;
    v_file_handle UTL_FILE.file_type;
    invalid_path EXCEPTION;
    mesg_length_exceeded BOOLEAN := FALSE;
    l_msg VARCHAR2 (32000);
    l_tag_sep VARCHAR2 (1)
    := func_get_config_value ('TAGSEPRTR');
    l_ind VARCHAR2 (10);
    l_rec VARCHAR2 (4000);
    l_sep_rep VARCHAR2 (4000) := '17_ACCSTMT_NOV_2010';
    l_rem_rep VARCHAR2 (4000);
    l_rep VARCHAR2 (4000);
    l_mim_type VARCHAR2 (2000);
    boundary CONSTANT VARCHAR2 (256)
    := '-----DMW.Boundary.605592468';
    first_boundary CONSTANT VARCHAR2 (256) := '--' || boundary || crlf;
    last_boundary CONSTANT VARCHAR2 (256)
    := '--' || boundary || '--' || crlf;
    multipart_mime_type CONSTANT VARCHAR2 (256)
    := 'multipart/mixed; boundary="' || boundary || '"';
    mime_type VARCHAR2 (255) := 'text/html';
    l_offset NUMBER;
    l_ammount NUMBER;
    CURSOR cur_trnm
    IS
    SELECT trnm_email_enarr, trnm_email_anarr
    FROM trnm
    WHERE trnm_id = 16;
    l_enarr trnm.trnm_email_enarr%TYPE;
    l_anarr trnm.trnm_email_enarr%TYPE;
    l_message_body VARCHAR2 (32000);
    --// To check if all mails belongs to the customer already sent...
    CURSOR cur_pdfd
    IS
    SELECT COUNT (*)
    FROM pdfd
    WHERE pdfd_cust_nb = p_cust_nb
    AND pdfd_email_sts IS NULL
    --NEWLY ADDED ...
    AND NVL (pdfd_stmt_mode, '.') = 'E'
    AND TRUNC (pdfd_to_dt) = (SELECT MAX (TRUNC (pdfd_to_dt))
    FROM pdfd
    WHERE pdfd_cust_nb = p_cust_nb);
    l_cnt NUMBER := 0;
    PROCEDURE send_header (NAME IN VARCHAR2, header IN VARCHAR2)
    IS
    BEGIN
    UTL_SMTP.write_data (conn, NAME || ': ' || header || crlf);
    END;
    PROCEDURE write_raw (
    p_conn IN OUT NOCOPY UTL_SMTP.connection,
    p_message IN RAW
    IS
    BEGIN
    UTL_SMTP.write_raw_data (p_conn, p_message);
    END write_raw;
    PROCEDURE binary_attachment (
    p_conn IN OUT UTL_SMTP.connection,
    p_file_name IN VARCHAR2,
    p_mime_type IN VARCHAR2
    IS
    k_max_line_width CONSTANT PLS_INTEGER DEFAULT 54;
    v_amt BINARY_INTEGER := 672 * 3;
    /* ensures proper format; 2016 */
    v_bfile BFILE;
    v_file_len PLS_INTEGER;
    v_buf RAW (2100);
    v_buf1 RAW (2100);
    v_modulo PLS_INTEGER;
    v_pieces PLS_INTEGER;
    v_file_pos PLS_INTEGER := 1;
    v_data RAW (32767);
    v_data1 RAW (32767);
    v_chunks PLS_INTEGER;
    l_amt NUMBER := 32767;
    l_off NUMBER := 1;
    l_raw RAW (32767);
    l_raw1 RAW (32767);
    l_lob BLOB;
    l_lob_empt BLOB;
    req UTL_HTTP.req;
    resp UTL_HTTP.resp;
    resp_empt UTL_HTTP.resp;
    l_url VARCHAR2 (4000);
    l_rep_path VARCHAR2 (2000);
    l_report VARCHAR2 (100);
    l_seq_nb repq.repq_seq_nb%TYPE;
    l_parm repq.repq_parm_val%TYPE;
    l_repq repq%ROWTYPE;
    l_sts NUMBER;
    l_user VARCHAR2 (10);
    --L_MSG VARCHAR2(32000);
    l_seq_id NUMBER;
    usr_err EXCEPTION;
    --// 07-Jun-2009 - Basheer A.S. : Code added for sending A/c Statement and PFL statements in single e-mail ...
    CURSOR cur_pdfd
    IS
    SELECT
    --UTL_COMPRESS.LZ_UNCOMPRESS(PDFD_DB_FILE) PDFD_DB_FILE,
    pdfd_file_name
    FROM pdfd
    WHERE pdfd_cust_nb = p_cust_nb
    --AND PDFD_EMAIL_STS IS NULL
    --NEWLY ADDED ...
    --AND NVL(PDFD_STMT_MODE,'.') = 'E'
    AND pdfd_seq_nb = p_seq_id
    AND TRUNC (pdfd_to_dt) = (SELECT MAX (TRUNC (pdfd_to_dt))
    FROM pdfd
    WHERE pdfd_cust_nb = p_cust_nb);
    l_buffer_size INTEGER := 57;
    l_offset INTEGER := 1;
    l_raw RAW (57);
    l_file_nm pdfd.pdfd_file_name%TYPE;
    BEGIN
    --// 06-Jun-2009 - Basheer A.S. : Code added for sending A/c Statement and PFL statements in a single e-mail ...
    --// Initializing temporary CLOB data ...
    DBMS_LOB.createtemporary (l_lob, FALSE);
    --DBMS_LOB.createtemporary(L_LOB_EMPT, FALSE);
    --// Loop thro all the records for the given Customer Number...
    OPEN cur_pdfd;
    LOOP
    --FETCH CUR_PDFD INTO L_LOB, L_FILE_NM;
    FETCH cur_pdfd
    INTO --L_LOB_EMPT,
    l_file_nm;
    EXIT WHEN cur_pdfd%NOTFOUND;
    proc_audit_log ('T',
    'PROC_MAIL_ATTACH_PDFS, Customer No. '
    || p_cust_nb
    || ', File attachment: '
    || l_file_nm
    UTL_SMTP.write_data (conn, first_boundary);
    UTL_SMTP.write_data (conn,
    'Content-Transfer-Encoding: base64 '
    || UTL_TCP.crlf
    UTL_SMTP.write_data (conn,
    'Content-Type: ' || mime_type || UTL_TCP.crlf
    UTL_SMTP.write_data (conn,
    'Content-Disposition: ATTACHMENT; filename="'
    || p_file_name
    || '"'
    || UTL_TCP.crlf
    UTL_SMTP.write_data (conn, crlf);
    l_ind := '1.1';
    v_file_pos := 1;
    --// Attaching individual PDF files ...
    BEGIN
    v_modulo := 0;
    v_pieces := 0;
    v_amt := 2016;
    l_ind := '2.1';
    v_file_len := DBMS_LOB.getlength (l_lob);
    --v_file_len := dbms_lob.getlength(L_LOB_EMPT);
    v_modulo := MOD (v_file_len, v_amt);
    v_pieces := TRUNC (v_file_len / v_amt);
    IF (v_modulo <> 0)
    THEN
    v_pieces := v_pieces + 1;
    END IF;
    l_ind := '2.2';
    DBMS_LOB.READ (l_lob, v_amt, v_file_pos, v_buf);
    --dbms_lob.read(L_LOB_EMPT, v_amt, v_file_pos, v_buf);
    v_data := v_data1;
    v_chunks := 0;
    v_data := v_data1;
    FOR i IN 1 .. v_pieces
    LOOP
    v_file_pos := i * v_amt + 1;
    v_file_len := v_file_len - v_amt;
    v_data := UTL_RAW.CONCAT (v_data, v_buf);
    l_ind := '2.3';
    v_chunks := TRUNC (UTL_RAW.LENGTH (v_data) / k_max_line_width);
    IF (i <> v_pieces)
    THEN
    v_chunks := v_chunks - 1;
    END IF;
    l_ind := '2.4';
    write_raw (p_conn => p_conn,
    p_message => UTL_ENCODE.base64_encode (v_data)
    v_data := v_data1;
    IF (v_file_len < v_amt AND v_file_len > 0)
    THEN
    v_amt := v_file_len;
    END IF;
    l_ind := '2.5';
    DBMS_LOB.READ (l_lob, v_amt, v_file_pos, v_buf);
    --DBMS_LOB.READ(L_LOB_EMPT, v_amt, v_file_pos, v_buf);
    END LOOP;
    EXCEPTION
    WHEN OTHERS
    THEN
    proc_audit_log
    ('E',
    'PROC_MAIL_ATTACH_PDFS.binary_attachment.inside BLOB loop, :'
    || SQLERRM
    || ',ind:'
    || l_ind
    END;
    v_file_pos := 1;
    UTL_SMTP.write_data (conn, UTL_TCP.crlf);
    UTL_SMTP.write_data (conn, UTL_TCP.crlf);
    END LOOP;
    --// END multiple file attachments
    l_ind := '2.6';
    UTL_SMTP.write_data (p_conn, last_boundary || UTL_TCP.crlf);
    EXCEPTION
    WHEN OTHERS
    THEN
    proc_audit_log ('E',
    'PROC_MAIL_ATTACH_PDFS, when others:'
    || l_ind
    || ', '
    || SQLERRM
    END binary_attachment;
    BEGIN
    --// If no pending emails for the given Customer, then exit the process...
    OPEN cur_pdfd;
    FETCH cur_pdfd
    INTO l_cnt;
    CLOSE cur_pdfd;
    --// If still pending statements needs to be send...
    --IF L_CNT > 0 THEN
    IF l_cnt = 0
    THEN
    OPEN cur_trnm;
    FETCH cur_trnm
    INTO l_enarr, l_anarr;
    CLOSE cur_trnm;
    l_message_body :=
    '<html>'
    ||
    --'<meta http-equiv="Content-Type" content="text/html; charset=WINDOWS-1256(Arabic)">'||
    --'<meta http-equiv="Content-Type" content="text/html; charset=WINDOWS-1256">'||
    '<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-6">'
    || '<body>
    <TABLE BORDER="0" WIDTH=100% style="table-layout:fixed;">
    <TR>
    <TD WIDTH="50%" ALIGN="LEFT" style="word-wrap: break-word"><B>'
    || l_enarr
    || '</B></TD>'
    || '<TD WIDTH="50%" ALIGN="RIGHT" style="word-wrap: break-word"><B>'
    || l_anarr
    || '</B></TD></TR></TABLE>
    </body>
    </html>';
    proc_audit_log ('T', 'PROC_MAIL_ATTACH_PDFS, msg:' || l_msg);
    v_smtp_server := func_get_config_value ('MAILHOST');
    v_smtp_server_port := func_get_config_value ('MAILPORT');
    l_ind := '3.1';
    conn := UTL_SMTP.open_connection (v_smtp_server, v_smtp_server_port);
    --utl_smtp.helo( conn, v_smtp_server );
    --utl_smtp.mail( conn, '[email protected]' );
    UTL_SMTP.helo (conn, v_smtp_server);
    UTL_SMTP.mail (conn, from_name);
    UTL_SMTP.rcpt (conn, to_name);
    l_ind := '3.2';
    l_rec := func_eti_tagval (l_msg, 'EMAIL');
    proc_audit_log ('T', 'PROC_MAIL_ATTACH_PDFS, l_rec:' || l_rec);
    proc_audit_log ('T', 'l_sep_rep1' || l_sep_rep);
    UTL_SMTP.open_data (conn);
    send_header ('From', '<' || from_name || '>');
    send_header ('To', '<' || to_name || '>');
    --send_header('To',''||Func_Eti_Tagval(L_MSG, 'EMAIL')||'');
    send_header ('Date', TO_CHAR (SYSDATE, 'dd Mon yy hh24:mi:ss'));
    send_header ('Subject', subject);
    send_header ('Content-Type', multipart_mime_type);
    UTL_SMTP.write_data (conn, first_boundary);
    --utl_smtp.write_data(conn, 'Content-Type: '||mime_type||utl_tcp.crlf);
    --utl_smtp.write_data(conn, 'Content-Type: '||mime_type||'; charset=Windows-1256'||utl_tcp.crlf);
    UTL_SMTP.write_data (conn,
    'Content-Type: '
    || mime_type
    || '; charset=ISO-8859-6'
    || UTL_TCP.crlf
    --new...
    UTL_SMTP.write_data (conn, crlf);
    UTL_SMTP.write_raw_data (conn, UTL_RAW.cast_to_raw (l_message_body));
    UTL_SMTP.write_data (conn, crlf);
    UTL_SMTP.write_data (conn, crlf);
    proc_audit_log ('T', 'l_sep_rep2' || l_sep_rep);
    binary_attachment (p_conn => conn,
    p_file_name => l_sep_rep || '.pdf',
    p_mime_type => 'multipart/mixed'
    ); --||l_sep_rep||'.pdf');
    UTL_SMTP.write_data (conn, last_boundary || UTL_TCP.crlf);
    UTL_SMTP.close_data (conn);
    UTL_SMTP.quit (conn);
    END IF;
    p_ret_cd := 0;
    p_ret_desc := 'Mail sent successfully';
    EXCEPTION
    WHEN OTHERS
    THEN
    proc_audit_log ('E',
    'PROC_MAIL_ATTACH_PDFS, error:'
    || SQLERRM
    || 'ind:'
    || l_ind
    p_ret_cd := 1;
    END;
    Kindly help me to resolve this issue.
    Thanks & Regards
    Ariff

    pl ease check below link
    /people/thomas.jung3/blog/2004/09/08/sending-e-mail-from-abap--version-610-and-higher--bcs-interface

  • Compressing blob field in an existing table

    Hi,
    I have a table of 1.5TB that contains blob field in binary format. I want to compress the BLOB field to save disk space. The oracle version is 10.2.Can anyone help me out.
    Thanks in advance.
    Siddh

    There is a package utl_compress that is able to compress blobs.
    if performance is not a problem then you can store all the blobs as compressed. And then add a view to this table that uncompresses the blob data during the select.
    If you upgrade to 11g there is also a cost option to compress the data on a tablespace level. See also: http://www.oracle.com/technetwork/database/features/storage/advanced-compression-whitepaper-130502.pdf

Maybe you are looking for

  • Allocating an item as a resource in Project 2010

    Hello I am trying to construct a Master Project Program using a resource pool. The sub projects are various manufacturing programs using common resources. Some of the resources I want to use are materials, specifically key production areas of a fixed

  • Default values in Account creation page

    Hello. I'm new to CRM and this forum too. I need some guidance. I have to set default values in account creation page. For this, I thought to use DO_INIT_CONTEXT method. And, when I searched this forum, I see a lot of threads about BADI CRM_BP_UIU_DE

  • Invoice without FD01?

    We have a customer where was billed without FD01. My FI analyst only noticed this issue when he tried to create a return invoice when did not let him to complete the process. Even with only the VD01, the invoice was created for this customer with no

  • Photoshop File Error-1 in Encore CS6 Menus / General Error

    Greetings, I recently had to install the whole CS again. I have had the program work previously before but with these issues now, I am lead to believe it is some installation issue. I will go to File-> New ->Menu. Then create a new timeline, import a

  • Big Problem getting songs onto Ipod..

    Ok, my other Ipod broke and i just recently got a new replacement. When i plug it into my computer, it starts updating. However, after about maybe 10-15 songs, a screen will come up saying "attempting to copy to the disk 'mikes ipod'failed. The disk