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

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
     
     
    ADVERTISEMENT

    Generate data entry and reporting .NET Web apps in minutes, straight from your database. Read our FREE whitepaper “Build Web 2.0 Applications Without Hand-Coding” Download now!

    Database Interaction with PL/SQL: Introduction to Sub-programs - More sub-programs


    (Page 5 of 5 )

    How many sub-programs can we write within a single program? The answer is AS MANY AS YOU CAN. You can declare and define any number of sub-programs within a single main program. There is no limit at all. Let us consider the following example:

    declare

                x          number := 30;

                y          number := 40;

               

                procedure displaySum as

                            a          number := 10;

                            b          number := 20;

                begin

                            dbms_output.put_line('Sum of numbers :' || (a+b+x+y) );

                end;

                procedure displayProduct as

                            a          number := 10;

                            b          number := 20;

                begin

                            dbms_output.put_line('Product of numbers :' || (a*b*x*y) );

                end;

                procedure displayAvg as

                            a          number := 10;

                            b          number := 20;

                begin

                            dbms_output.put_line('Avg of numbers :' || ((a+b+x+y)/4) );

                end;

               

    begin

                displaySum;

                displayProduct;

                displayAvg;

    end;

    Even though the above program is bit lengthy, the concept is very simple. I just used three sub-programs, namely ‘displaySum’, ‘displayProduct’ and ‘displayAvg’.  Each of those sub-programs has its own declarations of variables and logic. And I am calling all the sub-programs from within the main program.

    There is no particular order you can call a sub-program from within the main program. You can call sub-programs in any order without regard to the order (of the sub-programs) you defined.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · 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





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