Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


Streamline Your Oracle Production Code with Conditional Compilation : Page 3

Every Oracle PL/SQL developer concerned about the performance impact of repeated if... then... else calls can use conditional compilation to scrub these calls from production code. And that's just the beginning.


WEBINAR: On-Demand

Unleash Your DevOps Strategy by Synchronizing Application and Database Changes REGISTER >

Using Conditional Compilation Flags

In the conditional compilation IF-test, and elsewhere in the code, you can also use static expressions that are passed directly to the compiler at compile-time, not set in any PL/SQL code. Three options are available:
  • PL/SQL Compiler initialization parameters, such as NLS_Length_Semantics
  • User-defined conditional compilation flags, or ccflags
  • Oracle's two predefined ccflags, PLSQL_Unit and PLSQL_Line

You reference these non-PL/SQL expressions using the inquiry directive, or $$. That is, you preface a ccflag or a PL/SQL Compiler initialization parameter with $$. This signals the conditional compilation engine to reads its value in at compile-time, for example:

$IF $$PLSQL_LINE=15 $THEN debug('That was line 15'); $END ;

You set user-defined ccflags by assigning a string of name-value pairs to the Oracle parameter PLSQL_CCFLAGS in the format 'name:value[,name:value][,name:value]....'. For example, to set the values of ccflags named "set_debug_on", "use_10g_features", and "compile_w_extras", you would set PLSQL_CCFLAGS as follows:

PLSQL_CCFLAGS = 'set_debug_on:true,use_10g_features:false,compile_w_extras:false' ;

You can set PLSQL_CCFLAGS at the session or system level with ALTER SESSION or ALTER SYSTEM, respectively. Or, you can set PLSQL_CCFLAGS at compile time, for individual package or procedure compilation.

Here's an example of setting user-defined ccflags at compile time:

SQL> alter package PAYROLL_CALC compile 2> plsql_ccflags = 3> 'no_commit_trans:true,print_debug_msg:true' 4> reuse settings ;

Here's an example of setting the value of PLSQL_CCFLAGS at the ALTER SESSION level:

SQL> alter session set PLSQL_CCFLAGS = 2> 'set_debug_on:true' ;

And here's an example of setting the value of PLSQL_CCFLAGS at compile-time:

SQL> alter system set PLSQL_CCFLAGS = 2> 'use_10g_features:false' ;

You can combine package constants with ccflags in the conditional compilation IF-test, for example:

$IF $$DEBUG_ON or PayrollConstants.c_Debug $THEN debug('Error'); $END

You can set the package constant to TRUE during development and FALSE thereafter. After development, you can recompile the package with the ccflag DEBUG_ON set to TRUE whenever it's necessary for debugging. The following case study looks at this concept in more detail.

Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date