Conditional compilation of package

This tip was found in Oracle forums. With due respect to the author I am replicating the idea of the message below:

 

Oracle introduced conditional compilation of packages/procedures from 10g.

 

Conditional compilation allows PL/SQL code to be tailored to specific environments by selectively altering the source code based on compiler directives. It is considered a new feature of Oracle 10g Release 2, but is available in Oracle 10g Release 1 (10.1.0.4.0).

 

Compiler flags are identified by the "$$" prefix, while conditional control is provided by the $IF-$THEN-$ELSE syntax.

 

$IF boolean_static_expression $THEN text

  [ $ELSIF boolean_static_expression $THEN text ]

  [ $ELSE text ]

$END

 

Find below a simple example of procedure that uses conditional compilation. The objective of this package is to invalidate the package by not modifying the source/underlying objects.

 

SQL> create or replace package p is $IF ($$x) $then INVALID $else $end end;
 
Package created.
 
SQL> select status from user_objects where object_name='P';
 
STATUS
-------
VALID
 
SQL> alter package p compile PLSQL_CCFLAGS='x:true';
 
Warning: Package altered with compilation errors.
 
SQL> select status from user_objects where object_name='P';
 
STATUS
-------
INVALID

 

Thus without modifying the actual contents of the package we have been successful in invalidating the package.

 

More reads on:

Oracle Forum Topic

Oracle-Base