How can store sqlplus query in a file in formatted manner and display it to console up vote

I am trying to write a script which will connect to database and store the query output in a file in formatted manner

My expected file would be something like below:

LAST                         MONTHLY
NAME                          SALARY  COMMISSION
------------------------- ----------  ----------
Russell                        14000         .4
Partners                       13500         .3
Errazuriz                      12000         .3
Cambrault                      11000         .3
Zlotkey                        10500         .2

So far I have tried this.

sqlplus user/password@(TNS Entry) << EOF
SET head OFF;
SET feed OFF;
SET trimspool ON;
SET linesize 32767;
SET pagesize 32767;
SET echo OFF;
SET termout OFF;
SET verify OFF;
SET NEWPAGE NONE;
SET verify off;
spool file_name.csv
select * from Customer;
spool off

EXIT;
EOF

I am trying to display CSV file to console. But, it is not in a formatted style.

How can i achieve this ?


Source: shell

Leave a Reply