Problem in formatting output of SQL query in excel sheet in shell script

Hi Guys..

Need your help to format the output of my shell script.

I am using spool command to take out put in csv file.

below is my code. (for example)

col USERNAME for a15
col EMAIL for a30
col FULL_NAME for a20
col LAST_LOGIN for a40
col DATE_CREATED for a40
SPOOL 120.csv
select USERNAME||','||EMAIL||','||FULL_NAME||','||LAST_LOGIN||','||DATE_CREATED from abctable where (trunc(sysdate) -trunc(Last_login))>120 and status = 'Active'
and username not in (select username from scm_authorized_keys)
and ID not in (SELECT distinct created_by_id FROM audit_entry WHERE (TRUNC(SYSDATE) -TRUNC(date_created)) < 120);
SPOOL OFF

but output is not looking as i am expecting.. Moreover.. it is giving title of the column for every single entry. Please find attached sheet.

I need help to remove.

  1. Highlighted redundancy of column Title
  2. pipe symbol which is appearing to and forth of column title.
  3. want to do exact formatting in seperate columns. ( getting date created details down to user name).

Thanks in advance!

p.s. Used alphabetic to show the user names.

Cheers
ash

Hi

Some problem with the attachment. Not able to open it.

Regarding the title column appearing for every single entry, change your "pagesize" value. Set a huge value to pagesize, something like:

set pagesize 1000
col USERNAME for a15
col EMAIL for a30
col FULL_NAME for a20
col LAST_LOGIN for a40

....

Guru.

1 Like
USERNAME||'	'||EMAIL||'	'||FULL_NAME||'	'||LAST_LOGIN||'
--------------------------------------------------------------------------------			
abcdef	abcdef@yahoo.com	abcdef abc	29-SEP-11 03.2
9.35.613000 PM	08-JUL-10 03.43.59.000000 PM                                     		
================================================================

Thanks Guruprasad.. that worked!
now.. about another queries..
I have pasted output of one record as above.
Some fields are nt coming just below to the column Title. I checked column width and set accordingly. still no luck.
Pls temme if you can get anythin on it.
Also, pls let me know if there is syntax to set a col width for date and times. because.. those two fields say about dates and times.

Hi

  1. Regarding the fields not coming below the column title, the default linesize in sqlplus is 80. Looks your output line is more than 80 bytes. Set the linesize to a bigger value say 100. I mean, after the pagesize setting line, add the below line and check:
set linesize 100
  1. Regarding the date formatting, I do not think you can format it like you do for a varchar or a number field. You need to change the NLS_DATE_FORMAT. To change NLS_DATE_FORMAT, you can google and see, you will find lots

Guru.

1 Like