Skip to Main Content
  • Questions
  • Spool sql query output in single excel file but in two separate work sheets

Breadcrumb

XMAS_TREE

The AskTOM team is taking a break over the holiday season, so we're not taking questions or responding to comments. Please have a happy and safe festive season and as always, thanks for being a member of the AskTOM community.

Question and Answer

Chris Saxon

Thanks for the question, Sagar.

Asked: April 07, 2020 - 7:42 am UTC

Last updated: April 07, 2020 - 10:58 am UTC

Version: 11.2.0.4.0

Viewed 10K+ times! This question is

You Asked

I have written shell script which connect to Oracle DB (11g) and spool output into excel (.csv / .xls). This works perfectly fine to fetch data in single excel file.
I want to enhance my script which will connect to DB and execute 2 different queries which will spool the output into single excel file , but in 2 separate work sheets.
Is there any way to achieve this ? I have already tried to find some solutions but no luck so far.
Since I want to implement this is live production server, I cannot use any third party packages

e.g.
Query 1 : SELECT * from EMP; -> Output to Sheet1
Query 2 : SELECT * from DEPT; -> Output to Sheet2


and Chris said...

I believe it's not possible with spool.

You can use the export option of SQL Developer though. Select the tables you want to export in the tree view, right click "Export". Then choose the Excel format and Save As single file.

Jeff Smith goes into more detail at:

https://www.thatjeffsmith.com/archive/2016/01/exporting-multiple-tables-to-multiple-excel-spreadsheets/

We're not taking comments currently, so please try again later if you want to add a comment.

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