Exforsys

H I D E

Home arrow Technical Training arrow Oracle 11g Tutorial

Conditional compilation in Oracle PL/SQL Page - 3

Page 3 of 3
Author: Saurabh Gupta     Published on: 28th Jun 2011

Conditional compilation in Oracle PL/SQL

5. DBMS_PREPROCESSOR

It is an Oracle supplied package which enables to view the program source code as compiled by the compiler. It displays the actual portion of the code participating in the compilation process, after evaluation of all compilation conditions.

It contains two overloaded subprograms GET_POST_PROCESSED_SOURCE and PRINT_POST_PROCESSED_SOURCE. The structure of the overloaded subprograms is shown in the below snapshot.

For demonstration, Let's use procedure P_COND_COMPILE. This procedure declares a variable based on the database version, in which the procedure is executed. In Oracle9i and earlier version, it would be number. In 10g version, it would be BINARY_DOUBLE. Oracle 11g compiler would take the variable in SIMPLE_INTEGER format. Again, based on the database version, different values are assigned for different versions.

Sample Code
  1. CREATE OR REPLACE PROCEDURE P_COND_COMPILE
  2. IS
  3.    $IF DBMS_DB_VERSION.VERSION >= 11 $THEN
  4.         M_VERSION_PARAM SIMPLE_INTEGER := 0;
  5.    $ELSIF DBMS_DB_VERSION.VERSION BETWEEN 10 AND 11  $THEN
  6.         M_VERSION_PARAM BINARY_DOUBLE := 0;
  7.    $ELSE
  8.         M_VERSION_PARAM NUMBER;
  9.    $END
  10. BEGIN
  11.    $IF DBMS_DB_VERSION.VERSION >= 11 $THEN
  12.         M_VERSION_PARAM := 739202874;
  13.    $ELSIF DBMS_DB_VERSION.VERSION BETWEEN 10 AND 11 $THEN
  14.         M_VERSION_PARAM := 982.12247293721082739017372819102722191D;
  15.    $ELSE
  16.         M_VERSION_PARAM := 824.12247293721082739017372819102722191;
  17.    $END
  18.    DBMS_OUTPUT.PUT_LINE(M_VERSION_PARAM);
  19. END;
Copyright exforsys.com


Now, we can print the actual procedure source code as evaluated and compiled by the compiler using DBMS_PREPROCESSOR package.

The snapshot below is the compiled in Oracle 11g database. Note that the non applicable code of the procedure, thus redundant, has been ignored.

The snapshot below shows the code as compiled in Oracle 10g database. Note the changes in the variable declaration and value assignment.

Ads

The conditional compilation feature has surely eased the way for migration projects. For a usual patch release in a project or code testing, conditional compilation is a feature to be hunted.

Read Next: Oracle Pragma


 
This tutorial is part of a Oracle 11g Tutorial tutorial series. Read it from the beginning and learn yourself.

Oracle 11g Tutorial

 

Comments