Using Native Compilation

In pre-Oracle9i versions, compilation of PL/SQL source code always results in a representation (usually referred to as bytecode) that is stored in the database and is interpreted at runtime by a virtual machine implemented within Oracle that, in turn, runs natively on the given platform. Oracle9i introduces a new approach. PL/SQL source code may optionally be compiled into native object code that is linked into Oracle. (Note, however, that an anonymous PL/SQL block is never compiled natively.)

When would this feature come in handy? How do you turn on native compilation? This section addresses these questions.

PL/SQL is often used as a thin wrapper for executing SQL statements, setting bind variables, and handling result sets. For these kinds of programs, the execution speed of the PL/SQL code is rarely an issue; it is the execution speed of the SQL that determines the performance. (The efficiency of the context switch between the PL/SQL and the SQL operating environments might be an issue, but this is addressed very effectively by the FORALL and BULK COLLECT features introduced in Oracle8i and described in Chapter 13).

There are many other applications and programs, however, that rely on PL/SQL to perform computationally intensive tasks that are independent of the database. PL/SQL is, after all, a fully functional procedural language. Suppose, for example, that I wrote a program to find all right-angled triangles with all side lengths integer (a.k.a. perfect ...

Get Oracle PL/SQL Programming, Third 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.