19.2. Declarative Programming in PL/SQL

When you call a PLVexc exception handler, you shift from a procedural to a declarative style of programming in PL/SQL. To understand what I mean, think about the SQL language. You do not write programs in SQL. Instead, you use a declarative syntax to describe the set of data you want to see or modify. The underlying SQL engine then figures out the best way to accomplish the task. This declarative or "set at a time" mode of processing is a critical element of the power of the SQL language.

PL/SQL is very different from SQL. It is a procedural programming language. When you want to get something done in PL/SQL, you write a program. This gives you a tremendous amount of control, but it definitely cuts into your productivity—and offers many over-ripe opportunities for introducing bugs into your code. Wouldn't it be wonderful to combine the control of the procedural language with the high-level abstraction and productivity of a declarative syntax? Well, we are not talking idle chatter here. We are talking packages.

Constructed properly, the PL/SQL package offers the opportunity for developers to write code in a declarative style. Take a look again at the exception section that utilizes PLVexc. To write this code, a user of PLVexc only had to know what kind of action she wanted to perform. Ignore the error? Record and continue? Record and halt? Just describe the action desired, pass the necessary data, and then let the underlying engine (the ...

Get Advanced Oracle PL/SQL Programming with Packages 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.