Packages : Packages « Function Procedure Packages « Oracle PL/SQL Tutorial

  1. Packages encapsulate related functionality into one self-contained unit.
  2. Packages are typically made up of two components: a specification and a body.
  3. The package specification contains information about the package.
  4. The package specification lists the available procedures and functions.
  5. These are potentially available to all database users.
  6. The package specification generally doesn't contain the code.
  7. The package body contains the actual code.


SQL> create or replace package pkg_test1
  2  as
  3      function getArea (i_rad NUMBER) return NUMBER;
  4      procedure p_print (i_str1 VARCHAR2 :='hello',
  5                         i_str2 VARCHAR2 :='world',
  6                         i_end VARCHAR2  :='!' );
  7  end;
  8  /

Package created.

SQL> create or replace package body pkg_test1
  2  as
  3      function getArea (i_rad NUMBER)return NUMBER
  4      is
  5          v_pi NUMBER:=3.14;
  6      begin
  7         return v_pi * (i_rad ** 2);
  8      end;
 10      procedure p_print(i_str1 VARCHAR2 :='hello',
 11                        i_str2 VARCHAR2 :='world',
 12                        i_end VARCHAR2  :='!' )
 13      is
 14      begin
 15          DBMS_OUTPUT.put_line(i_str1||','||i_str2||i_end);
 16      end;
 17  end;
 18  /

Package body created.

27.10.2.Private Versus Public Package Objects
27.10.3.Package State
27.10.4.Recompiling Packages
27.10.5.All packages can be recompiled by using the Oracle utility dbms_utility:
27.10.6.Creating a Package Specification
27.10.7.Creating a Package Body
27.10.8.Creating Packages and call its functions
27.10.9.Calling Functions and Procedures in a Package
27.10.10.A Package Specification and its body
27.10.11.Overloading Packaged Subprograms
27.10.12.Calls procedure in a package
27.10.13.Dropping a Package
27.10.14.Calling a Cursor Declared in a Different Package
27.10.15.Reference fields and methods in package
27.10.16.Controlling access to packages
27.10.17.Globals Stored in a Package
27.10.18.A Subtypes Example
27.10.19.Generate Random number
27.10.20.Crosss reference between two packages
27.10.21.package RECURSION
27.10.22.Using RESTRICT_REFERENCES in a Package
27.10.23.PLS-00452: Subprogram 'GETNAME' violates its associated pragma
27.10.24.Dynamically create packages