use bat file to write csv with sql data
1- write sql that will get data to csv
file name: allsql.sql
SET PAGESIZE 0;
SET LINESIZE 5000;
SET TRIMSPOOL ON;
SET TERMOUT OFF;
SET TIMING OFF;
SET FEEDBACK OFF;
spool file.csv;
# there are sql sentences here end with ;
# e.g.:
select * from u;
spool off;
quit;
2- login sql, execute sql, write to csv file and add headers
@echo off
sqlplus account/password@address @allsql.sql
:: generator the csv file
echo FIELD1,FIELD2>INDEX.csv
type index.csv >> INDEX.csv
del index.csv