Oracle
  Home arrow Oracle arrow Page 2 - Compiling PL/SQL Code for an Oracle Da...
Dev Shed Forums 
Administration  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
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: 5 stars5 stars5 stars5 stars5 stars / 4
    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:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb 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

    Route your faxes to your email inbox. Private, secure fax numbers available from CallWave. Choose your fax number.

    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 SESSION
        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
    querying 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 testing 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


       · This article is an excerpt from the book "Oracle PL/SQL Programming, Fourth...
     

    Buy this book now. This article 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). Check it out today at your favorite bookstore. Buy this book now.

       

    ORACLE ARTICLES

    - 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...
    - Sub-templates and More with Oracle HTML DB
    - Focusing on Templates in Oracle HTML DB




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway