Oracle
  Home arrow Oracle arrow Page 3 - Database Interaction with PL/SQL, User-defined Packages
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

Database Interaction with PL/SQL, User-defined Packages
By: Jagadish Chatarji
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 24
    2005-09-12


    Table of Contents:
  • Database Interaction with PL/SQL, User-defined Packages
  • Database interaction using a PACKAGE
  • Overloading sub-programs in a PACKAGE
  • TYPE declarations in package specification
  • How the above package works

  • 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


    Database Interaction with PL/SQL, User-defined Packages - Overloading sub-programs in a PACKAGE
    (Page 3 of 5 )

    Those who are familiar with Object Oriented Programming (OOP) can easily understand the concept of overloading.  Briefly, having the same name for different sub-programs with different parameters can be called overloading sub-programs.  The following example gives you an illustration:

    create or replace package SamplePkg as
        procedure dispEmp;
        procedure dispEmp(p_deptno dept.deptno%type);
    end SamplePkg;
    /

    create or replace package body SamplePkg as
         procedure dispEmp as
             cursor c_emp is
                 select ename, sal from emp;
         begin
             for r_emp in c_emp
             loop
                 dbms_output.put_line (r_emp.ename || ',' || r_emp.sal);
             end loop;
          end;

          procedure dispEmp(p_deptno dept.deptno%type) as
              cursor c_emp is
                  select ename, sal from emp
                  where deptno = p_deptno;
          begin
              for r_emp in c_emp
              loop
              dbms_output.put_line (r_emp.ename || ',' || r_emp.sal);
              end loop;
          end;

    end SamplePkg;
    /

    Within the above package, we declared two sub-programs as having the same name.  But you should observe that the first sub-program doesn’t have any parameters, whereas the second sub-program does.  If you execute with the following statement:

    Execute SamplePkg.dispEmp;

    It would automatically call the first sub-program (because you didn’t provide any parameters).  If you execute with the following statement:

    Execute SamplePkg.dispEmp(10);

    It would automatically choose the second sub-program (because we provided a parameter).

    So, the selection of the respective sub-program will be automatically chosen by PL/SQL runtime based on the parameters we send.  In that way, we can write as many sub-programs as possible with the same name, but with some differences in parameters.



     
     
    >>> More Oracle Articles          >>> More By Jagadish Chatarji
     

       

    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-2010 by Developer Shed. All rights reserved. DS Cluster 11 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek