Sql is a declarative language. Oracle has tightly integrated its sql with a procedural language (PL/SQL) which can be used to write applications. Pl/sql provides structures for conditional control through the use of If logic, iterative control through looping for repeated process execution, and sequential control through Goto statements (which transfer control) and Null statements (to perform no action). Errors can be trapped and resolved by exception handlers.

Individual components of pl/sql are organized into modular blocks demarked by begin and end statements. Procedural blocks perform particular actions; functional blocks return values. Modularization of code allows small, comprehensible steps to be combined into complex operations. The way modules are designed affects development time, reuseability, and maintainability.

Sql is a set-at-a-time database language. single rows from a select statement's result set cannot be individually examined or modified. Procedural languages operate on only a single table row at a time. To gain finer control, pl/sql employs cursors. Cursors act like pointers that locate specific table rows and allow for operations on them by feeding results to a procedural language for processing. Cursor is a synonym for context area - a work area in memory where Oracle stores the current sql statement. For a query, the area includes column headings and one row retrieved by the select statement.


 

Stored procedures and database triggers are statements that reside inside a database where they can be used by multiple applications. These offer a prime example of the performance gain associated with the shared pool, i.e., the reuse of identical queries from parsed versions of executed commands.

Pl/sql plays an important role in maintaining the integrity of an Oracle database. In the real world, grants and locks cannot guarantee the integrity of a transaction that spans more than one table. Stored procedures provide users with only so-called execute (or run) authority, while programs reside inside a database to act, in effect, as gatekeepers. Users are granted the authority to execute procedures, not update tables.

A package is a collection of modules, cursors, variables, and other objects. This is a very powerful construct that sadly is often misunderstood and underutilized by developers. Packages allow you to hide code and focus user attention elsewhere, abstract records and tables into variable form, and improve performance through, e.g., use of the shared global area, a section of memory employed in much the same way as sql uses the shared pool.