Packages in PLSQL
Packages in PLSQL
- SOHEL DESHMUKH
Introduction to Packages
- 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
PackageName.ElementName;
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.