1 2 Previous Next 16 Replies Latest reply on May 21, 2009 1:50 AM by 345641

    Create Zip File


      I need to zip a folder using the Oracle Code.
      Is it possible to do that?
      If it is possible please give your sugessions.

      Thanks in Advance.

        • 1. Re: Create Zip File
          UTL_COMPRESS Package
          This new package delivers the familiar functionality of zip and unzip utilities in a PL/SQL environment. It lets you compress and uncompress a RAW bytestream, and guarantees the exact original bytestream after the round trip. This package also handles lobs, and has features to add and later extract several pieces into a single archive.
          • 2. Re: Create Zip File
            Hi ,
            If you use Oracle Forms , then you can achieve this with DDE forms built-in package or HOST procedure...
            Refer to Forms documentation to find out the syntax and examples...

            • 3. Re: Create Zip File
              I have a similar requirement, i.e. to extract the data from a file inside a zip file. As far as I understand it UTL_COMPRESS does not support extracting a compressed file from a zip file. Zip files created with a utility like WinZip performs two tasks: Compression and Archiving. UTL_COMPRESS does the compression part but not the archiving. Do I understand this correctly?

              Is there another PL/SQL API that I can use to extract files from a Zip archive?
              • 4. Re: Create Zip File
                Did you try UTL_COMPRESS.lz_uncompress?
                • 5. Re: Create Zip File
                  Yes I did try UTL_COMPRESS.lz_uncompress. So I got an invalid data error. But apart from that, the UTL_COMPRESS API does not support listing or extracting files from an archive. It does support a piecewise extract but this did not work either and there is no way to specify a specific file to extract. Or please tell me I am missing something?
                  • 6. Re: Create Zip File
                    Did you use UTL_COMPRESS to compress the file that you're trying to extract? I tried the example in this link and it works for me.
                    • 7. Re: Create Zip File
                      No, as I said before I am trying to unzip a file that was created with a program like Winzip, i.e. a file like aaa.zip.
                      • 8. Re: Create Zip File

                        I use a home-made java code in database for zipping. But I don't unzip...
                        • 9. Re: Create Zip File
                          What about zip in Oracle 9i? Is that UTL package avilable in Oracle 9i?


                          Satyaki De.
                          • 10. Re: Create Zip File

                            Unfortunately there is a known bug which doesn't allow you to uncompress WINZIP files: <p>Utl_compress.Lz_uncompress Is Not Able To Unzip Windows Zip Files Ora-29294
                            • 11. Re: Create Zip File
                              Schedule a vb-script or .bat to uncompress the file at a given time, then use the UTL_COMPRESS to compress it and then you can decompress it with oracle when you want.
                              • 12. Re: Create Zip File
                                The above link is a HOWTO entry and not a "known bug".

                                I may be missing something but I still cannot see how the UTL_COMPRESS package in principle can handle zip archives. In order to do so would require a function to list the contents of the archive, i.e. the individual files within the zip file.
                                • 13. Re: Create Zip File
                                  The above link is a HOWTO entry and not a "known bug".
                                  You are right: maybe it is more of a restriction than a bug.
                                  Anyway, I tried the following which works per se, but the output is not a valid zip file, eventhough the data is compressed.

                                  For compression I did:
                                     f              UTL_FILE.file_type;
                                     compressed     BLOB;
                                     uncompressed   BLOB               := UTL_RAW.cast_to_raw ('HelloWorld');
                                     f := UTL_FILE.fopen ('TEMP', 'HelloWorld.zip', 'wb');
                                     DBMS_LOB.createtemporary (compressed, FALSE);
                                     UTL_COMPRESS.lz_compress (uncompressed, compressed, 6);
                                     UTL_FILE.put_raw (f, compressed);
                                     UTL_FILE.fclose (f);
                                     DBMS_LOB.freetemporary (compressed);
                                  For uncompression I did:
                                     f              UTL_FILE.file_type;
                                     compressed     BLOB;
                                     uncompressed   BLOB;
                                     fexists        BOOLEAN;
                                     file_length    NUMBER;
                                     block_size     BINARY_INTEGER;
                                     UTL_FILE.fgetattr ('TEMP',
                                     f := UTL_FILE.fopen ('TEMP', 'HelloWorld.zip', 'rb');
                                     UTL_FILE.get_raw (f, compressed, file_length);
                                     uncompressed := UTL_COMPRESS.lz_uncompress (compressed);
                                     DBMS_OUTPUT.put_line (UTL_RAW.cast_to_varchar2 (uncompressed));
                                     UTL_FILE.fclose (f);
                                  As said, you can read and write from the "zip" file, but no file listing (as you noted yourself) is available. But maybe, if one elaborates more on this, one can modify the bytestream to add some zip headers to make the file zip-compatible ...
                                  • 14. Re: Create Zip File

                                    I'm aware of but haven't used utl_compress, but it makes sense that it wont handle archives.

                                    With that limitation in mind, I would go down the path of calling an OS utility from the database. There are several methods for making OS calls from the database (note that this is the OS for the database server) and several ways of doing this from the client (ie Oracle Forms) but I don't see the point. Just zip it locally.

                                    1 2 Previous Next