sqlplus – produce clean extract file

syntax
sqlplus -S <userid>/<password>@<database> @<sql-file> > <output-file> 2> /dev/null
example
sqlplus -S <meuser>/<mepass>@<medatabase> @<mequery.sql> > <meoutput.dat> 2> /dev/null

 

The below lines need to be at the top of the sql-file to ensure the output-file is formatted correctly.

-S
set echo off
set newpage 0
set pagesize 0
set heading off
set linesize 10000
set space 0
set feedback off
set verify off
– Flag suppresses oracle banner and trailer.
– Suppresses the display of commands in a script that is executed with @, @@ or START.
– Places a formfeed at the beginning of each page (including the first page) and clears the screen on most terminals.
– Suppress all headings, page breaks, titles, the initial blank line, and other formatting information.
– Suppresses the printing of the column header.
– Sets the total number of characters that SQL*Plus displays on one line before beginning a new line.
– Not sure.
– Turns off the statement confirmation messages and number of records affected messages.
– Suppresses the listing of the text of a SQL statement or PL/SQL command before and after replacing substitution variables with values.