Windows command-line

guylav

Member
Hi all,
I need to execute many plsql in a windows batch file and I need the output in an excel format. Can you help me ?
 
Consider using SQL*Plus instead.

Code:
set termout off
set heading off
set feedback off
set pagesize 0
set linesize 2000
set trimspool on
spool data.csv
SELECT	'id,first name,last name'
FROM	DUAL;
SELECT	employee_id || ',',
	'"' || REPLACE(first_name, '"', '""') || '",',
	'"' || REPLACE(last_name, '"', '""') || '"'
FROM	EMPLOYEE;
spool off
exit
This works for us. Ensure that linesize is set big enough to cover a whole line of data. The stuff involving double quotes is necessary to make a valid .csv file. If you know your data won't contain double quotes, you don't have to replace them. If you additionally know your data won't contain newlines and commas, you don't have to wrap that data in double quotes.

Edit: Oops. Left out the commas.
 
Back
Top