SQL*Plus was not designed to be a tool used for writing complex scripts. Its capabilities cannot compare to those of your typical Unix shell, such as the Korn shell or the Bourne shell. Nor does it have anywhere near the capabilities of an advanced scripting tool such as Perl. Most noticeably, SQL*Plus suffers from the following limitations:
It lacks an IF statement.
There are no looping constructs.
It has very limited error handling.
There is only marginal support for validating user input.
Because of these limitations, SQL*Plus is best suited to executing top-down scripts that don’t require any branching, looping, or error handling. Most of the scripts you have seen so far in this book fall into this category. Many are reports that simply set up some column and page formatting, then execute a query. If something goes wrong, you either don’t see any data in the report or may see some SQL or SQL*Plus error messages.
This limited scripting support is fine when it comes to producing a report. After all, if a report fails, you can simply fix the problem and rerun the report. But what if you are performing a more complex and critical task? What if you are summarizing some data, posting the summary results to a summary table, and then deleting the underlying detail? In that case, you certainly wouldn’t want to delete the data if the summarization failed. You would need some sort of error-handling mechanism.
If you need to write scripts of any significant ...