f you're an Oracle PL/SQL developer, you have two familiar needs:
- Include as much debugging code as possible without risking a performance hit when the code is running in production
- Create code that takes advantage of the newest features in the latest Oracle Database versions but still runs on older versionswithout creating "bloatware" that stuffs the shared pool with separate code for each database version
Developers working in other languages have long had an easy solution that addresses both these needs: the preprocessor or precompiler. For example, the C++ preprocessor can handle conditional compilation directives and string substitution, which allow developers to compile different subsets of the source code for development, production, different DB versions, and so on. But Oracle PL/SQL has been missing this capabilityuntil now.
The recently released Oracle Database10gR2 has a new feature that makes it easy to meet these needs: PL/SQL conditional compilation (CC). PL/SQL CC is not technically a precompiler or preprocessor; it's functionality that Oracle added to the earliest stages of the existing PL/SQL compilation process. The same engine carries it out along with the other stages. However, PL/SQL is sometimes referred to as a preprocessor, as in the name of the
DBMS_PREPROCESSOR package (more on that later).
This article shows you how to use Oracle 10gR2's new CC feature, how to view the results of conditional compilation with
DBMS_PREPROCESSOR, how to leverage this new feature with
DBMS_DB_VERSION to create version-independent code, and how to use conditional compilation to create a lightweight debugging framework.