Home arrow Oracle arrow Page 2 - Conditional Compilation for Oracle Database 10g

Examples of Conditional Compilation - Oracle

In this fifth part of a nine-part series on PL/SQL, you'll learn how conditional compilation lets you compile selected parts of a program when you're working with Oracle Database 10g. It is excerpted from chapter 20 of the book Oracle PL/SQL Programming, Fourth Edition, written by Steven Feuerstein and Bill Pribyl (O'Reilly; ISBN: 0596009771). Copyright © 2006 O'Reilly Media, Inc. All rights reserved. Used with permission from the publisher. Available from booksellers or direct from O'Reilly Media.

TABLE OF CONTENTS:
  1. Conditional Compilation for Oracle Database 10g
  2. Examples of Conditional Compilation
  3. The Inquiry Directive
  4. Setting compilation environment parameters
By: O'Reilly Media
Rating: starstarstarstarstar / 6
November 15, 2007

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

Letís start with some examples of several types of conditional compilation.

Use application package constants in $IF directive

The $IF directive can reference constants defined in your own packages. In the example below, I vary the way that the bonus is applied depending on whether or not the location in which this third-party application is installed is complying with the Sarbanes-Oxley guidelines. Such a setting is unlikely to change for a long period of time. If I rely on the traditional conditional statement in this case, I will leave in place a branch of logic that should never be applied. With conditional compilation, the code is removed before compilation.

  /* File on web: cc_my_package.sql */
  CREATE OR REPLACE PROCEDURE apply_bonus (
    id_in IN employee.employee_id%TYPE
   
,bonus_in IN employee.bonus%TYPE)
  IS
  BEGIN
    
UPDATE employee
       
SET bonus =
         $IF employee_rp.apply_sarbanes_oxley
         $THEN
            LEAST (bonus_in, 10000)
         $ELSE
            bonus_in
         $END
       WHERE employee_id = id_in;
    NULL;
  END apply_bonus;
  /

Toggle tracing through conditional compilation flags

We can now set up our own debug/trace mechanisms and have them conditionally compiled into our code. This means that when our code rolls into production, we can have this code completely removed, so that there will be no runtime overhead to this logic. Note that I can specify both Boolean and PLS_INTEGER values through the special PLSQL_CCFLAGS compile parameter.

  /* File on web: cc_debug_trace.sql */
  ALTER SESSION SET PLSQL_CCFLAGS = 'oe_debug:true, oe_trace_level:10';

  CREATE OR REPLACE PROCEDURE calculate_totals
  IS
  BEGIN
  $IF $$oe_debug AND $$oe_trace_level >= 5
  $THEN
    
DBMS_OUTPUT.PUT_LINE ('Tracing at level 5 or higher');
  $END
    
NULL;
  END calculate_totals;
  /



 
 
>>> More Oracle Articles          >>> More By O'Reilly Media
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

ORACLE ARTICLES

- Oracle Java Security Woes Continue
- Oracle's New IaaS Cloud Option: There's a Ca...
- Oracle Acquires Eloqua to Boost Cloud Presen...
- Choosing Innovation: Oracle Survey Insights
- Oracle Fixes Privilege Escalation Bug
- Oracle`s Communications Service Availability...
- Oracle Releases Exalytics, Taleo Plans
- Oracle Releases Communications Network Integ...
- Oracle Releases Communications Data Model 11...
- Oracle Releases PeopleSoft PeopleTools 8.52
- Oracle Integrates Cloudera Apache Distro, My...
- Oracle Releases MySQL 5.5.18
- Oracle Announces NoSQL Database Availability
- Sorting Database Columns With the SELECT Sta...
- Retrieving Table Data with the LIKE Operator

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: