0% found this document useful (0 votes)
146 views

Packages in PLSQL

Packages in PL/SQL organize related objects like variables, cursors, procedures and functions into a single unit. A package has a specification that declares public objects and a body that defines private objects and implements cursors and subprograms. Packages provide reusability, encapsulation, modularity and improved performance by minimizing unnecessary recompiling. The package specification declares public objects accessible from outside while the body defines queries for cursors and code for subprograms declared in the specification. Variables can be package variables shared among all procedures and functions, or local variables only accessible within their declaring procedure or function.

Uploaded by

sam
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
146 views

Packages in PLSQL

Packages in PL/SQL organize related objects like variables, cursors, procedures and functions into a single unit. A package has a specification that declares public objects and a body that defines private objects and implements cursors and subprograms. Packages provide reusability, encapsulation, modularity and improved performance by minimizing unnecessary recompiling. The package specification declares public objects accessible from outside while the body defines queries for cursors and code for subprograms declared in the specification. Variables can be package variables shared among all procedures and functions, or local variables only accessible within their declaring procedure or function.

Uploaded by

sam
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 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