Looking for good programming challenges?

Use the search below to find our solutions for selected questions!

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

sqlplus username/password@SERVER SQL> @path/to/script.sql