Unzip file using AS_ZIP package and insert into table

309 Views Asked by At

I have a .zip file in a table and I'm trying to figure out how to unzip that file using the AS_ZIP package.

I know how to compress using that package but I don't know how to decompress, any ideas?

1

There are 1 best solutions below

0
Cesar Tepetla On

I have managed to unzip a zip file from a table, this is the code:

DECLARE
  v_doc BLOB;
  zip_files as_zip.file_list;
BEGIN
    SELECT FILE_CONTENT INTO v_doc FROM ZIPPED_FILES WHERE FILE_NAME ='Test.zip';
  zip_files  := as_zip.get_file_list( v_doc );
  FOR i IN zip_files.FIRST() .. zip_files.LAST
  LOOP
        --dbms_output.put_line(DBMS_LOB.SUBSTR(zip_files(i).filename,2000,1) ||' '|| TO_CHAR(zip_files(i).datemaj,'DD/MM/RRRR HH24:MI:SS') ||' size:'|| zip_files(i).size_comp ||' / '|| zip_files(i).size_uncomp);
    dbms_output.put_line( utl_raw.cast_to_varchar2( as_zip.get_file(v_doc, zip_files(i))));
  END LOOP;
END;