Chapter 11. Advanced Scripting

SQL*Plus was not designed to be a tool used for writing complex scripts. Its capabilities can't 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 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 set up some column and page formatting and then execute a query. If something goes wrong, you may not see any data in the report, or you 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 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 don't want to delete the data if the summarization failed. You need some kind of error-handling mechanism.

Tip

If you need to write scripts of any significant complexity, I strongly encourage ...

Get Oracle SQL*Plus: The Definitive Guide, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.