Oracle
  Home arrow Oracle arrow Database Interaction with PL/SQL: Intr...
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 
IBM Developerworks
 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

Database Interaction with PL/SQL: Introduction to Sub-programs
By: Jagadish Chatarji
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 18
    2005-08-09

    Table of Contents:
  • Database Interaction with PL/SQL: Introduction to Sub-programs
  • Coding our first sub-program
  • Variables and scope in sub-programs
  • Variable scope bit in depth
  • More sub-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
     
     
    FaxWave - Free Trial.
     
    ADVERTISEMENT

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

    Database Interaction with PL/SQL: Introduction to Sub-programs
    (Page 1 of 5 )

    This is part 12 of a series of articles focusing on database interactions with Oracle PL/SQL. In my previous article, I looked at several examples of explicit cursors. I also introduced the concept of cursors with parameters. In this article we will look into sub-programs. Mainly we will concentrate on procedures and discuss some issues of variable scoping with respect to sub-programs.

    Actually, I need to discuss the concept of REF CURSOR at this moment, but the REF CURSOR is mainly used in sub-programs (or even packages). So, I thought to discuss the sub-programs and packages before going to REF CURSOR.

    Please note that all the examples in this series have been tested only with Oracle 10g. I didn’t really test them with all the previous versions of Oracle. I suggest you to refer the documentation of respective version you are using, if any of the programs failed to execute.

    Introduction to sub-programs

    Almost every programming language supports sub-programs. They are a part of structured programming. A sub-program is a part of a main program separated completely from the main program. We can consider it as separate block of statements (with its own declarations and programming statements), but still under the control of the main program.

    The above explanation may match a bit with anonymous blocks (or nested blocks) of PL/SQL programs (discussed in my previous set of articles), but sub-programs are totally different from nested blocks.  Nested blocks would definitely execute within the main block. But a sub-program need not do so. How is this possible?

    It's really quite simple. As I explained earlier, it is a separate block, separately named, and the main issue is that it is separately called by the main block. The main block calls the sub-program by its name to execute its set of statements. This may be a part of the conditions as well.  That means the main program may or may not call sub-program based on certain conditions.

    Why is this concept necessary? Repeatable tasks (or the tasks which are being executed quite frequently) are generally separated as sub-programs to facilitate the user to use them as many times as possible.  This also improves the clarity (or readability) of the main program, which is being divided into several meaningful tasks, where each task (sub-program) may have its own set of programming statements (including local declarations).

    This concept is mainly taken from the initiative of modularization. It is the process by which you break up large blocks of code into smaller pieces called modules (or sub-programs) which can be called by other modules. With the concept of modularization, our code becomes more reusable, more manageable, more readable and finally more reliable.  This is not only for sub-programs; it is being implemented in the form of packages (to be dealt with in my upcoming articles) as well.

    There are mainly two kinds of sub-programs: procedures and functions.  Both are very similar in functionality and syntactical issues. The one difference is that a function returns a value, but a procedure doesn’t.  We will look into the concept of functions in-depth later.

    More Oracle Articles
    More By Jagadish Chatarji


       · Hello guys, this is my article introducting sub-programs in PL/SQL. You can start...
       · Please write an article on REF Cursor explaining it in detail and in what different...
       · Thanks for your interest. You will have them soon...
     

       

    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

     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




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