Packages :
1. Specification (required)
2. Body (optional)
(i) Information hiding : Implementation is hidden in the package body.
(ii) Public and private : Specification (public) & Body (private).
(iii) Initialization: package is initialized only once per session.
(iv) Session persistence : If we establish a session and execute a program that assigns a value to a package-level variable,
that variable is set to persist for the length of the session, and it retains its value even if the
program that performed the assignment has ended.
Example:
create or replace package test_package
as
my_variable1 number;
my_variable2 varchar2(200);
end;
/
Session 1:
Begin
test_package.my_variable1:=1;
test_package.my_variable2:='kiran';
End;
/
Begin
dbms_output.put_line(test_package.my_variable1);
dbms_output.put_line(test_package.my_variable2);
End;
/
Session 2:
Begin
dbms_output.put_line(test_package.my_variable1);
dbms_output.put_line(test_package.my_variable2);
End;
/
Note:
The first time our session uses a package (whether by calling a program defined in the package, reading or writing a variable, or using a locally declared variable TYPE), Oracle initializes that package.
A package may be reinitialized in a session if that package was recompiled since last use
or
if the package state for our entire session was reset.
No comments:
Post a Comment