Re: Condition Compilation Question

  • From: Jason Heinrich <jheinrich@xxxxxxxx>
  • To: <post.ethan@xxxxxxxxx>, oracle-l <oracle-l@xxxxxxxxxxxxx>
  • Date: Tue, 15 May 2007 11:41:26 -0500

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.
> 
> http://www.oracle.com/technology/pub/articles/10gdba/nanda_10gr2dba_part1.html
> #compile  
> <http://www.oracle.com/technology/pub/articles/10gdba/nanda_10gr2dba_part1.htm
> 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

Other related posts: