SunQuest
 
       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  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Actuate Whitepapers 
VeriSign Whitepapers 
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

Working With PL/SQL Code
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 5
    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:
      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

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    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


       · 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