Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 9

Packages in PL/SQL

- SOHEL DESHMUKH
Introduction to Packages

In Oracle packages are a way to organize related PL/SQL objects into a


single unit.
A package includes variables, constants, cursors, exceptions, procedures,
functions, and subprograms.
It is compiled and stored in the Oracle Database.
Typically, a package has a specification and a body.
Advantages

- Reusability
- Encapsulation
- Modularity and Maintainability
- Improved Performance
- Minimize unnecessary recompiling code
Package specification
The package specification declares the public objects that are accessible from outside
the package.
If a package specification whose public objects include cursors and subprograms, then it
must have a body which defines queries for the cursors and code for the subprograms.
Package body
A package body contains the implementation of the cursors or subprograms declared in
the package specification. In the package body, you can declare or define private
variables, cursors, etc., used only by package body itself.
Packages Structure

The following picture illustrates PL/SQL packages:


Steps in Package Creation & Execution
Using the Package Elements

PackageName.ElementName;

Example for package we created in last slide we can execute by:-

DECLARE
cust_id customers.id%type := &cc_id;
BEGIN
cust_sal.find_sal(cust_id);
END;
/
Types of Variables

Package Variables:
Variables declared within the Package Body but outside any specific procedure or
function. They are shared among all the procedures and functions within the package.
Local Variables:
Variables declared within a specific procedure or function inside the Package Body. They
are accessible only within the scope of the procedure or function where they are
declared.
Parameters:
Parameters are placeholders for values that are passed to a procedure or function when
they are called.
Thank You.

You might also like