Oracle
  Home arrow Oracle arrow Page 3 - 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 - The Inquiry Directive
    ( Page 3 of 4 )

    An inquiry directive is a directive that makes an inquiry of the compilation environment. Of course, that doesn’t really tell you much. So let’s take a closer look at the syntax for inquiry directives and the different sources of information available through the inquiry directive.

    The syntax for an inquiry directive is as follows:

      $$identifie r

    where identifier is a valid PL/SQL identifier that can represent any of the following:

    1. Compilation environment settings: the values found in the USER_PLSQL_OBJECT_SETTINGS data dictionary view
    2. Your own custom-named directive, defined with the ALTER...SET PLSQL_CCFLAGS command, described in a later section
    3. Implicitly defined directives: $$PLSQL_LINE and $$PLSQL_UNIT, providing you with the line number and program name

    Inquiry directives are designed for use within conditional compilation clauses, but they can also be used in other places in your PL/SQL code. For example, I can dis play the current line number in my program with this code:

      DBMS_OUTPUT.PUT_LINE ($$PLSQL_LINE);

    I can also use inquiry directives to define and apply application-wide constants in my code. Suppose, for example, that the maximum number of years of data supported in my application is 100. Rather than hardcode this value in my code, I could do the following:

      ALTER SESSION SET PLSQL_CCFLAGS = 'max_years:100';

      CREATE OR REPLACE PROCEDURE work_with_data (num_years_in IN PLS_INTEGER )
      IS
      BEGIN
        
    IF num_years_in > $$max_years THEN ...
      END work_with_data;

    Even more valuable, I can use inquiry directives in places in my code where a vari able is not allowed. Here are two examples:

      DECLAR E
         l_big_string VARCHAR2($$MAX_VARCHAR2_SIZE);

         l_default_app_err EXCEPTION;
        
    PRAGMA EXCEPTION_INIT (l_default_app_err, $$DEF_APP_ERR_CODE);
      BEGIN

    The DBMS_DB_VERSION package

    The DBMS_DB_VERSION built-in package offers a set of constants that give you absolute and relative information about the version of your installed database. The constants defined in the Oracle Database 10g Release 2 version of this package are shown in Table 20-2.

    Table 20-2. DBMS_DB _VERSION constants

    Name of packaged constant

    Significance

    Value in Oracle Database10g Release 2

    DBMS_DB_VERSION.VERSION

     The RDBMS version number, as in 10 for Oracle Database 10g

    10

    Table 20-2. DBMS_DB _VERSION constants (continued)

    Name of packaged constant

    Significance

    Value in Oracle Database 10g Release 2

    DBMS_DB_VERSION.RELEASE

    The RDBMS release number, as in 2 for Oracle Data-base 10gRelease 2

    2

    DBMS_DB_VERSION.VER_LE_9

    TRUE if the current version is less than or equal to Oracle9iDatabase

    FALSE

    DBMS_DB_VERSION.VER_LE_9_1

    TRUE if the current version is less than or equal to Oracle9iDatabase Release 1

    FALSE

    DBMS_DB_VERSION.VER_LE_9_2

    TRUE if the current version is less than or equal to Oracle9iDatabase Release 2

    FALSE

    DBMS_DB_VERSION.VER_LE_10

    TRUE if the current version is less than or equal to Oracle Database 10g

    TRUE

    DBMS_DB_VERSION.VER_LE_10_1

    TRUE if the current version is less than or equal to Oracle Database 10g Release 1

    FALSE

    DBMS_DB_VERSION.VER_LE_10_2

    TRUE if the current version is less than or equal to Oracle Database 10gRelease 2

    TRUE

    While this package was designed for use with conditional compilation, you can, of course, use it for your own purposes.

    With each new release of the database, Oracle will add additional constants and will update the values returned by the VERSION and RELEASE constants.

    Interestingly, you can write expressions that include references to as-yet undefined constants in the DBMS_DB_VERSION package. As long as they are not evaluated, as in the case below, they will not cause any errors. Here is an example:

      $IF DBMS_DB_VERSION.VER_LE_10_ 2
      $THEN
        
    Use this code.
      $ELSEIF DBMS_DB_VERSION.VER_LE_11
        
    This is a placeholder for future.
      $ENDIF



     
     
    >>> 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 6 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek