Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Mailing Lists -> Oracle-L -> Condition Compilation Question
I am reading the section regarding conditional compilation here.
http://www.oracle.com/technology/pub/articles/10gdba/nanda_10gr2dba_part1.html#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
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!
-- http://www.freelists.org/webpage/oracle-lReceived on Tue May 15 2007 - 10:32:32 CDT
![]() |
![]() |