Oracle
  Home arrow Oracle arrow Page 2 - Database Interaction with PL/SQL, Work...
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 
Moblin 
JMSL Numerical Library 
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, Working with TABLE in Sub-programs, Parameter Modes
By: Jagadish Chatarji
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 19
    2005-08-30

    Table of Contents:
  • Database Interaction with PL/SQL, Working with TABLE in Sub-programs, Parameter Modes
  • Returning PL/SQL TABLE from a FUNCTION to a PROCEDURE
  • What are IN types of parameters?
  • What are OUT types of parameters?
  • What is an IN OUT type of parameter?

  • 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


    Database Interaction with PL/SQL, Working with TABLE in Sub-programs, Parameter Modes - Returning PL/SQL TABLE from a FUNCTION to a PROCEDURE


    (Page 2 of 5 )

    In the previous section of this article, I used a PL/SQL TABLE as a parameter for the PROCEDURE.  Now, I shall revise the above stated program in such a way that I will use both FUNCTION and PROCEDURE together, communicating with PL/SQL TABLEs.  Let us consider the following example:

    declare

        type t_emptbl is table of emp%rowtype;
        procedure dispEmp(p_emptbl t_emptbl) is

        begin

            for i in p_emptbl.first .. p_emptbl.last

               loop

                   dbms_output.put_line(p_emptbl(i).ename ||
                   ' earns ' || p_emptbl(i).sal);

               end loop;

        end;

        function getEmployeeList return t_emptbl is

            v_emptbl          t_emptbl;                    

            begin

                select * bulk collect into v_emptbl from emp;

                return v_emptbl;

            end;

         BEGIN

            dispEmp(getEmployeeList);

         END;

     

    Let us examine the two sub-programs separately.

    procedure dispEmp(p_emptbl t_emptbl) is

        begin

           for i in p_emptbl.first .. p_emptbl.last

           loop

                                        dbms_output.put_line(p_emptbl(i).ename || ' earns ' || p_emptbl(i).sal);

           end loop;

        end;

    It just receives PL/SQL TABLE as parameter and displays all the information available in it.

    function getEmployeeList return t_emptbl is

             v_emptbl          t_emptbl;                     

        begin

             select * bulk collect into v_emptbl from emp;
             return v_emptbl;

         end;

    The above function ‘getEmployeeList’ executes the SELECT statement and the output is gathered into ‘v_emptbl’, which is returned back (or pushed out).

    dispEmp(getEmployeeList);

    The above is the most important statement in the program.  It looks very simple, but a lot of logic is embedded in it.  First of all, it executes the FUNCTION ‘getEmployeeList’.  That FUNCTION returns a PL/SQL TABLE, which will be sent as a parameter to the procedure ‘dispEmp’ automatically.  We need not actually store the PL/SQL TABLE returned by the FUNCTION.

    More Oracle Articles
    More By Jagadish Chatarji


       · Hello guys, this is my article on working with sub-programs with tables in PL/SQL....
     

       

    ORACLE ARTICLES

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





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