Oracle
  Home arrow Oracle arrow Page 3 - Working With PL/SQL Code
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

Working With PL/SQL Code
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 7
    2007-11-29


    Table of Contents:
  • Working With PL/SQL Code
  • Synchronizing Code with Packaged Constants
  • Working with Postprocessed Code
  • Testing PL/SQL Programs

  • 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


    Working With PL/SQL Code - Working with Postprocessed Code
    ( Page 3 of 4 )

    You can use the DBMS_PREPROCESSOR package to display or retrieve the source text of your program in its postprocessed form. DBMS_PREPROCESSOR offers two programs, overloaded to allow you to specify the object of interest in various ways, as well as to work with individual strings and collections:

    DBMS_PREPROCESSOR.PRINT_POST_PROCESSED_SOURCE

    Retrieves the postprocessed source and then displays it with the function DBMS_OUTPUT.PUTLINE.

    DBMS_PREPROCESSOR.GET_POST_PROCESSED_SOURCE

    Returns the postprocessed source as either a single string or a collection of strings.

    When working with the collection version of either of these programs, you will need to declare that collection based on the following package-defined collection:

      TYPE DBMS_PREPROCESSOR.source_lines_t IS TABLE OF VARCHAR2(32767)
         INDEX BY BINARY_INTEGER;

    The following sequence demonstrates the capability of these programs. I compile a very small program with a selection directive based on the optimization level. I then display the postprocessed code, and it shows the correct branch of the $IF statement.

      /* File on web: cc_postprocessor.sql  
      CREATE OR REPLACE PROCEDURE post_processed
      IS
      BEGIN
      $IF $$PLSQL_OPTIMIZE_LEVEL = 1
      $THEN 
         
    -- Slow and easy
       
    NULL;
      $ELSE
        
    -- Fast and modern and easy
        
    NULL;
     
    $END

      END post_processed;
      /

      SQL> BEGIN
       
    2     
    DBMS_PREPROCESSOR. PRINT_POST_PROCESSED_SOURCE (
       3         
    'PROCEDURE', USER, 'POST_PROCESSED');
       4  END;
       5
      /

      PROCEDURE post_processed
      IS
      BEGIN
      -- Fast and modern and easy
      NULL;
      END post_processed;

    In the following block, I use the “get” function to retrieve the postprocessed code, and then display it using DBMS_OUTPUT.PUT_LINE:

      DECLARE
         l_postproc_code      DBMS_PREPROCESSOR. SOURCE_LINES_T;
         l_row                PLS_INTEGER;
      BEGIN
        
    l_postproc_code := 
       DBMS_PREPROCESSOR.GET_POST_PROCESSED_SOURCE (
          'PROCEDURE', USER, 'POST_PROCESSED');
         l_row := l_postproc_code.FIRST;

         WHILE (l_row IS NOT NULL)
         LOOP
           
    DBMS_OUTPUT.put_line ( LPAD (l_row, 3)
                                 || ' - '
                                 || rtrim ( l_postproc_code (l_row),chr(10))
                               
    );
            l_row := l_postproc_code.NEXT (l_row);
         END LOOP;
      END;
      /

    Conditional compilation opens up all sorts of possibilities for PL/SQL developers and application administrators. And its usefulness only increases as new versions of Oracle are released and the DBMS_DB_VERSION constants can be put to full use, allowing us to take full advantage of each version’s unique PL/SQL features.



     
     
    >>> 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