Oracle
  Home arrow Oracle arrow Page 2 - Conditional Compilation for Oracle Database 10g
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
Google.com  
ORACLE

Conditional Compilation for Oracle Database 10g
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 5
    2007-11-15


    Table of Contents:
  • Conditional Compilation for Oracle Database 10g
  • Examples of Conditional Compilation
  • The Inquiry Directive
  • Setting compilation environment parameters

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Conditional Compilation for Oracle Database 10g - Examples of Conditional Compilation
    ( Page 2 of 4 )

    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
     

       

    ORACLE ARTICLES

    - Oracle's Turn to Play in the Sun
    - Implementing and Using Oracle`s Restore Poin...
    - Tuning PL/SQL Code
    - Debugging PL/SQL Code
    - Testing PL/SQL Code
    - Working With PL/SQL Code
    - Conditional Compilation for Oracle Database ...
    - Compile-Time Warnings for Oracle DB 10g
    - Compiling PL/SQL Code for an Oracle Database
    - Troubleshooting PL/SQL Code
    - Managing PL/SQL Code
    - Data Manipulation and More for HTML DB Appli...
    - Oracle Database Fundamentals
    - Adding Processes to HTML DB Applications
    - Adding Computations, Processes, and Validati...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek