Skip to Main Content
  • Questions
  • Zip a .csv file present at DB directory using PL/SQL

Breadcrumb

Question and Answer

Chris Saxon

Thanks for the question, Amar.

Asked: May 07, 2021 - 4:20 am UTC

Last updated: November 07, 2025 - 1:54 pm UTC

Version: 19c

Viewed 1000+ times

You Asked

We have a requirement where we are generating .csv file from DB and placed it to a DB directory. We want to zip these .csv files so that size can be optimised. Could you please suggest a way to achieve it by using PL/SQL.

and Connor said...

Check out Anton's zip package - its pretty cool

https://github.com/antonscheffer/as_zip

Rating

  (1 rating)

Is this answer out of date? If it is, please let us know via a Comment

Comments

wrong github

Anton, November 07, 2025 - 1:05 pm UTC

Although yallie was the first to place my zip package on github the best place to get it since 2018 is no doubt https://github.com/antonscheffer/as_zip

With for instance a procedure to create a csv file and directly zip it.

Anton
declare
  l_zip blob;
  l_rc sys_refcursor;
begin
  for f in 1 .. 5
  loop
    open l_rc for
      select level r, 'test "' || level l, sysdate + level n
      from dual connect by level <= f;
    --
    as_zip.add_csv( l_zip, l_rc, 'file' || f || '.csv', 'This is csv-file ' || f );
  end loop;
  --
  as_zip.save_zip( l_zip, 'VAGRANT', 'zip4.zip' );
  dbms_lob.freetemporary( l_zip );
end;

Chris Saxon
November 07, 2025 - 1:54 pm UTC

Thanks for letting us know Anton - I've updated the link

More to Explore

PL/SQL demos

Check out more PL/SQL tutorials on our LiveSQL tool.

PL/SQL docs

PL/SQL reference manual from the Oracle documentation library