I have a small batch file that runs a query when the user invokes it. This batch file contains sqlplus commands and spools the results of the query into a file called "data.csv". The colsep is set to ',' and so i have a neat little excel-like report for this special user.
Now the problem is this :-
the spool file automatically pads each result cell to its table description. For eg.
as you can see , there are unsightly spaces before "1" and after "Rose"...the total space between commas is the column length -- ie the flower_id field will always have 10 chars (either numbers or padding spaces) in it. The Flower_Name is actually varchar2(255) so you can imagine how awkward it is in the csv file....with 251 spaces after "Rose" and "Lily".
I have tried everything from setting the COL format to A5 , or trimming all over the place....but there is no way i have been able to remove the annoying padding spaces.
I dont intend to touch the base table/create views on it because this is not something we can do in the prod database.
Do you have a solution for this? Please let me know.
Regards,
S. Jayaram Uparna .
Now the problem is this :-
the spool file automatically pads each result cell to its table description. For eg.
Code:
Table Flowers :-
-----------------------
Create Table Flowers
(
Flower_ID number(10),
Flower_Name varchar2(20),
Flower_date date
)
data in the table
--------------------------
1 Rose 10-Jun-05
2 Lily 12-Jun-05
query executed by the batch file :-
-------------------------------------
set trims on term off verify off line 10000 colsep ','
spool c:\data.csv
prompt flower_id,flower_name,flower_date
select flower_id,trim(flower_name),flower_date from Flowers ;
spool off;
result stored in data.csv :-
----------------------------------
flower_id,flower_name,flower_date
[COLOR=red yellow] [/color]1,Rose[COLOR=red yellow] [/color],10-Jun-05
[COLOR=red yellow] [/color]2,Lily[COLOR=red yellow] [/color],12-Jun-05
as you can see , there are unsightly spaces before "1" and after "Rose"...the total space between commas is the column length -- ie the flower_id field will always have 10 chars (either numbers or padding spaces) in it. The Flower_Name is actually varchar2(255) so you can imagine how awkward it is in the csv file....with 251 spaces after "Rose" and "Lily".
I have tried everything from setting the COL format to A5 , or trimming all over the place....but there is no way i have been able to remove the annoying padding spaces.
I dont intend to touch the base table/create views on it because this is not something we can do in the prod database.
Do you have a solution for this? Please let me know.
Regards,
S. Jayaram Uparna .