Oracle
  Home arrow Oracle arrow Database Interaction with PL/SQL, User...
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 
 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, User-defined Packages
By: Jagadish Chatarji
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 16
    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:
      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

    Database Interaction with PL/SQL, User-defined Packages
    (Page 1 of 5 )

    This article is part of a series focusing on database interactions with Oracle PL/SQL. In my previous article, we examined named notation, default values of parameters, stored procedures, stored functions and finally took our first look at package and package body. In this article, we will focus completely on package and package body. Before reading this article I suggest you to go through my last three articles in this series thoroughly.

    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 refer to the documentation for the respective version you are using, if any of the programs failed to execute.

    Implementing a PACKAGE

    In this section, we will look into the implementation of package in Oracle database. First of all, let us have a very simple example as follows:

    create or replace package SamplePkg as
        procedure dispSquare (a IN number);
        procedure dispCube (a IN number);
    end SamplePkg;
    /

    The above code actually creates only a package specification (not the body yet).  Consider the following code:

    create or replace package body SamplePkg as

        procedure dispSquare(a IN number) is
        begin
            dbms_output.put_line ('Square = ' || (a*a) );
        end;

        procedure dispCube(a IN number) is
        begin
            dbms_output.put_line ('Cube = ' || (a*a*a));
        end;
    end SamplePkg;
    /

    The above code creates the package body for the previous package specification.  All the members in the package body should match with all the declarations within the package specification.  Make sure that both package specification and package body gets stored in the database.

    Now the question is, how do we execute a package?  If it is a stored procedure, we just execute by using an ‘execute’ command (part 16) followed by the procedure name.  Even here, the concept is almost similar. The only issue is that we need to use the command ‘execute’ followed by the “packagename.sub-programname” convention.  The following is a demonstration for the above package to execute from SQL prompt:

    Execute SamplePkg.dispSquare(10);
    Execute SamplePkg.dispCube(10);

    More Oracle Articles
    More By Jagadish Chatarji


       · Hello guys, this is my new article on working with packages in PL/SQL. You can...
       · when i try one small example,it gives like thispackage,function,procedure and type...
     

       

    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