'Multiple spools in sqlplus

In a UNIX shell, I am trying to call several different sql queries, and then write the various results to separate csv files.

I have two sql files saved in the same directory as my master .sh script, called accounts.csv and display.csv, which each do simple queries of database tables.

select * from accounts

and then this master shell script which calls them both and, I'd like, writes them to csv files.

#!/bin/ksh
sqlplus -s user/password@DB <<EOF
set verify off
set linesize 5000
set heading on
set trimspool on
set pagesize 0
set colsep ,
set feedback off
set serveroutput on
SPOOL accounts.csv
@accounts.sql
SPOOL OFF
SPOOL display.csv
@display.sql
SPOOL OFF
exit


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source