Home » SQL & PL/SQL » SQL & PL/SQL » Export to CSV issue
Export to CSV issue [message #192451] Tue, 12 September 2006 08:02 Go to next message
Billy69
Messages: 1
Registered: September 2006
Location: Leicester, UK
Junior Member
Hi,

I'm having a problem with a little script I am writing in SQLPlus. I have a fair bit of experience with MS SQL, but am having an issue with converting to Oracle!

Basically, I need to extract data using a sql script into a CSV File. To do this, I have the following script:


set echo off heading off feedback off
spool c:\localdata\customer_data_out.csv
set newpage 0
set pagesize 0
set linesize 1000
set trimspool on
set space 0
SELECT DISTINCT rtrim(custrec.custNo,) as CustNum,
',',
custrec.DOB
FROM custrec
ORDER BY CustNum ASC
/
exit


I run this from the DOS command line using a scheduler.

My problem is that the first data field is padded, so the output I get in the csv file is like this:

012345666__________,01-NOV-88
(The _'s are actually spaces, but I can't seem to post extraneous spaces!)

Whereas I need to to be like this:

012345666,01-NOV-88

without the spaces

Also, the outputted csv appears to have an extra line break at the end of the file.

Any ideas?

Many thanks
David
Re: Export to CSV issue [message #192454 is a reply to message #192451] Tue, 12 September 2006 08:13 Go to previous message
Mahesh Rajendran
Messages: 10672
Registered: March 2002
Location: oracleDocoVille
Senior Member
Account Moderator
better approach.
http://asktom.oracle.com/~tkyte/flat/index.html

Previous Topic: query a table
Next Topic: Truncate trailing spaces on select
Goto Forum:
  


Current Time: Fri Dec 09 15:40:43 CST 2016

Total time taken to generate the page: 0.27652 seconds