Oracle FAQ Your Portal to the Oracle Knowledge Grid

Home -> Community -> Mailing Lists -> Oracle-L -> Re: Condition Compilation Question

Re: Condition Compilation Question

From: Jason Heinrich <>
Date: Tue, 15 May 2007 11:41:26 -0500
Message-ID: <>

No, the conditional compilation logic will only be executed when the procedure is compiled, meaning that either the ŒDebug=Tı line or the ŒDebug=Fı line will be in the compiled code, but not both. One thing this is good for is debug/test code that you donıt want to run on production. Using a package variable like he does in the example, you can specify which instance is Test and which is Live. Then when the code is loaded and compiled on live, the debug code will be excluded by the compiler, without you having to remember to remove it or comment it out.

On 5/15/07 10:32 AM, Ethan Post wrote:

> I am reading the section regarding conditional compilation here.
> #compile
> <
> l#compile>
> 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
> is
> debug_flag constant boolean := FALSE;
> end;
> 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
> as
> begin
> $if debug_pkg.debug_flag $then
> dbms_output.put_line ('Debug=T');
> $else
> dbms_output.put_line ('Debug=F');
> $end
> end;
> 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, execute:
> SQL> exec myproc
> Debug=F
> 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
> is
> debug_flag constant boolean := TRUE;
> end;
> Then, execute the procedure again:
> SQL> exec myproc
> Debug=T
> 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 automatically!

Jason Heinrich
Oracle Database Administrator
Pensacola Christian College
Received on Tue May 15 2007 - 11:41:26 CDT

Original text of this message