Call (800) 766-1884 for Oracle support & training
Free Oracle Tips

Oracle Consulting Support
Oracle Upgrades
Use New Oracle Features
Oracle Replication Support
Oracle Training
Remote Oracle DBA
System Documentation
Oracle Tips
Oracle Performance

Free Oracle Tips



BC Oracle tuning

Oracle training

Oracle support

Remote Oracle




EnterpriseDB: Declaring and Calling Packaged Code
Oracle Tips by Burleson

A package is best thought of as a library of code.  It's like a .jar file in Java or a .lib in many other languages.  It is a set of procedures, functions and variables stored together in a single unit.

While there is nothing magical about the package, there are some special features of SPL that you can only use when you take advantage of packages. 

* Encapsulation - Packages provide a separation between the public definition of a procedure or function and the actual implementation of that procedure or function

* Performance – When you call a single procedure or function in a package, the entire package is loaded into memory allowing faster response of the other related code

* Organization – Packages allow you to group related information together in a single unit

* Features – Packages allow you to have public and protected variables in addition to local variables and packages allow you to overload procedures and functions

Package Specification

The package specification defines the public view of your package.  In the specification, you will define any public variables and types and any public procedures and functions.

The package specification does not contain any executable code or exception handling.  The specification contains only the definitions of the items used in the public interface.  The syntax for a package specification is:


  [public type declaration]
  [public variable declaration]
  [public constant declaration]
  [public cursor declaration] 

  [PROCEDURE <procedure name>[(<variable list>)];] 

  [FUNCTION <function name>[(<variable list>)]
     RETURN <data type>;] 


A package specification is required to contain at least one definition of some sort but is not required to contain any specification definition.  That means that a specification may only contain a single variable definition.  If a specification does not contain a procedure or function definition, it will not have a package body.

Package Body

Package bodies follow the same block structure as anonymous blocks, procedures and functions.  A package body is NOT required for a specification.  

The package is where the executable code and exception handling for a package resides.  In addition to the public declarations, the package body may contain private functions and procedures that are not callable outside the package.  The syntax for a package body is:


  [private type declaration]
  [private variable declaration]
  [private constant declaration]
  [private cursor declaration] 

  [PROCEDURE <procedure name>[(<variable list>)]
     <executable and exception handling>;

  [FUNCTION <function name>[(<variable list>)]
     RETURN <data type>
     <executable and exception handling>;
     RETURN <return value>;

  <package initialization code>]


In addition to declaring private variables and providing the code for the procedures and functions, a package body contains an initialization section.  The initialization section can initialize any public or private variables and can perform any additional functionality that would normally be performed in a procedure, including running SQL commands.  The initialization section must contain at least one executable statement.

The procedures and functions in a package body are defined like a standalone procedure or function and perform in the same way.  Parameters are available and all three modes (IN, OUT and IN OUT) are allowed.


This is an excerpt from the book "EnterpriseDB: The Definitive Reference" by Rampant TechPress.


Oracle performance tuning software 

Oracle performance tuning book


Oracle performance Tuning 10g reference poster
Oracle training in Linux commands
Oracle training Excel
Oracle training & performance tuning books



Copyright © 1996 -  2014 by Burleson. All rights reserved.

Oracle® is the registered trademark of Oracle Corporation. 

Hit Counter