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

Breadcrumb

Question and Answer

Chris Saxon

Thanks for the question, Sagar.

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

Answered by: Chris Saxon - Last updated: April 07, 2020 - 10:58 am UTC

Category: SQL - Version: 11.2.0.4.0

Viewed 100+ times

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 we 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/