Oracle
  Home arrow Oracle arrow Page 2 - Compiling PL/SQL Code for an Oracle Database
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? 
ORACLE

Compiling PL/SQL Code for an Oracle Database
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 5
    2007-11-01


    Table of Contents:
  • Compiling PL/SQL Code for an Oracle Database
  • Interpreted Versus Native Compilation Mode
  • Using the Optimizing Compiler and Compile-Time Warnings
  • How to turn on compile-time warnings

  • 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


    Compiling PL/SQL Code for an Oracle Database - Interpreted Versus Native Compilation Mode
    ( Page 2 of 4 )

    After your administrator sets everything up, you are ready to go native. The first thing to do is set the compiler parameter. A user may set it as described here.

    In Oracle9i Database, specify:

      ALTER SESSIO N
        SET plsql_compiler_flags = 'NATIVE';  /* vs. 'INTERPRETED' */

    Starting with Oracle Database 10g Release 1, the PLSQL_COMPILER_FLAGS parameter is deprecated, so you should use this instead:

      ALTER SESSION
         SET plsql_code_type = 'NATIVE';   /* vs. 'INTERPRETED' */

    The compilation mode will then be set for subsequently compiled PL/SQL library units during that session, as long as they are compiled by one of the following:

    1. A script or explicit CREATE [OR REPLACE] command
    2. An ALTER... COMPILE statement
    3. The DBMS_UTILITY.COMPILE_SCHEMA packaged procedure

    In addition, the DBA can change the mode on a system-wide basis using ALTER SYSTEM.

    Oracle stores the compilation mode with the library unit’s metadata so that if the program is implicitly recompiled as a consequence of dependency checking, the last mode used will be used again. Note that this “stickiness” applies only to automatic recompilations; other rebuilds or recompiles will use the session’s current setting. You can determine the saved compilation mode for your stored programs by
    query ing the data dictionary using the statement shown here (for Oracle Database 10g):

      SELECT name, type, plsql_code_type
       
    FROM USER_PLSQL_OBJECT_SETTINGS
       
    ORDER BY name;

    The result will show something like this:  

    NAME

    TYPE PLSQL_CODE_TYPE

    -----------------------

    ------- ------------ ---------------------

    ANIMAL_HIST_TRG

    TRIGGER NATIVE

    DEMO

    PACKAGE BODY INTERPRETED

    DEMO

    PACKAGE INTERPRETED

    ORDER_SEEDS

    PROCEDURE NATIVE

    PLVTMR

    PACKAGE NATIVE

    PLVTMR

    PACKAGE BODY NATIVE

    PRINTANY

    FUNCTION INTERPRETED

    In Oracle9i Database, the WHERE clause would instead look for PLSQL_COMPILER_FLAGS, and you would get additional information about whether the unit has been compiled with debug mode.

    Incidentally, PL/SQL debuggers will not work with natively compiled programs. This is one of the only downsides to native compilation, but in most cases you could work around it by using interpreted mode during development, and native mode in test ing and production.

    Oracle recommends that all of the PL/SQL library units called from a given top-level unit be compiled in the same mode (see the sidebar “Converting an Entire Database to Native (or Interpreted)”). That’s because there is a cost for the context switch when a library unit compiled in one mode invokes one compiled in the other mode. Significantly, this recommendation includes the Oracle-supplied library units. These are always shipped compiled in interpreted mode because they may need to get recompiled during subsequent upgrades, and Oracle cannot assume that you have installed a supported C compiler.

    Our conclusion? If your application contains a significant amount of compute-intensive logic, consider switching your entire database—including Oracle’s supplied library units—to use native compilation. Making such a change is likely to offer the most dramatic performance improvements for applications that are unable to take advantage of the optimizing compiler introduced in Oracle Database 10g.


    Converting an Entire Database to Native (or Interpreted)

    The simplest way to follow Oracle’s recommendation that all PL/SQL library units called from a given top-level unit be compiled in the same mode is to convert the whole database so that all PL/SQL library units are compiled native, and to set the system-wide parameter PLSQL_COMPILER_FLAGS (Oracle9i Database) or PLSQL_CODE_TYPE (Oracle Database 10g) to NATIVE.

    While this is not technically difficult to do, it can be very time-consuming if you have a large number of modules. There are a number of nonobvious steps to the process; we suggest following Oracle’s explicit instructions closely.

    1. For Oracle9i Database: http://otn.oracle.com/tech/pl_sql/htdocs/README_ 2188517.htm
    2. For Oracle Database 10g: http://www.oracle.com/technology/tech/pl_sql/ htdocs/ncomp_faq.html#ncomping_db

    The latter link is actually part of a larger FAQ that contains a wealth of useful information on native compilation.




     
     
    >>> 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
    Stay green...Green IT