Oracle PL/SQL - PL SQL Statement Conditional Compilation

Introduction

In the following code, if you change the value of debug to FALSE and then recompile the two procedures.

The compiled code for my_proc1 changes, but the compiled code for my_proc2 does not.

Demo

SQL>
SQL> CREATE PACKAGE my_debug IS
  2    debug CONSTANT BOOLEAN := TRUE;-- w  w w. j  a  va2 s  . c o m
  3    trace CONSTANT BOOLEAN := TRUE;
  4  END my_debug;
  5  /

Package created.

SQL>
SQL> CREATE PROCEDURE my_proc1 IS
  2  BEGIN
  3    $IF my_debug.debug $THEN
  4      DBMS_OUTPUT.put_line('Debugging ON');
  5    $ELSE
  6      DBMS_OUTPUT.put_line('Debugging OFF');
  7    $END
  8  END my_proc1;
  9  /

Procedure created.

SQL>
SQL> CREATE PROCEDURE my_proc2 IS
  2  BEGIN
  3    $IF my_debug.trace $THEN
  4      DBMS_OUTPUT.put_line('Tracing ON');
  5    $ELSE
  6      DBMS_OUTPUT.put_line('Tracing OFF');
  7    $END
  8  END my_proc2;
  9  /

Procedure created.

SQL>

Related Topic