Generating CSV reports from SQL*Plus

Problem statement
Suppose you have a query whose result needs to be exported as a CSV file. In addition some fields need to be parsed into a different format and columns need to be renamed.

The SPOOL command
The SPOOL command causes SQL*Plus to write the results to a file.

Sample script

How to run the script

 

lucas