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 causes SQL*Plus to write the results to a file.
How to run the script
$ sqlplus username/password@SERVER $ SQL> @path/to/script.sql