RE: Condition Compilation Question

  • From: "Brady, Mark" <Mark.Brady@xxxxxxxxxxxxxxxxx>
  • To: <post.ethan@xxxxxxxxx>, "oracle-l" <oracle-l@xxxxxxxxxxxxx>
  • Date: Tue, 15 May 2007 12:38:51 -0400

Conditional compilation eliminates sections from the compiled code
entirely. If you flipped the debug_flag to TRUE, you 'd still be
printing Debug=F until you recompiled your source code. 





From: oracle-l-bounce@xxxxxxxxxxxxx
[mailto:oracle-l-bounce@xxxxxxxxxxxxx] On Behalf Of Ethan Post
Sent: Tuesday, May 15, 2007 11:33 AM
To: oracle-l
Subject: Condition Compilation Question


I am reading the section regarding conditional compilation here.

What is the difference for the example below and using a standard "if
then else"? Why would below  be better? Isn't it evaluated every time?


Let's examine another variation of this new feature. In addition to the
definition of a conditional variable, you can also check a static
constant of a package in the conditional compilation. For example,
suppose you want to control the debugging output of a PL/SQL procedure
based on a Boolean packaged constant. First you create the package as 

create or replace package debug_pkg


   debug_flag constant boolean := FALSE;


The debug_flag is the constant that determines the conditional logic in
the code. You can now embed the code inside the package as follows: 

create or replace procedure myproc



        $if debug_pkg.debug_flag $then 

                dbms_output.put_line ('Debug=T');


                dbms_output.put_line ('Debug=F');



Note that the packaged constant is referenced directly without any $
sign. In this case, there is no need to set any session- or system-level
conditional compilation parameters. While the function is compiled, you
do not need to pass any additional clause either. To see how this works,

SQL> exec myproc


Because the value of debug_pkg.debug_flag is FALSE now, the execution of
the procedure returned "F" as expected. Now, change the constant value: 

create or replace package debug_pkg


   debug_flag constant boolean := TRUE;


Then, execute the procedure again: 

SQL> exec myproc


The procedure picked up the value of the constant to show "T," as
expected. Note a very important difference here-you did not need to
recompile the procedure; the change to the constant was picked up

>>> This e-mail and any attachments are confidential, may contain legal,
professional or other privileged information, and are intended solely for the
addressee.  If you are not the intended recipient, do not use the information
in this e-mail in any way, delete this e-mail and notify the sender. CEG-IP2

Other related posts: