Package
Package
A Package is compiled and stored as a database object that can be used later.
Components of Packages :
-----------------------
Package Specification
Package Body
Package Specification :
----------------------
The elements which are all declared in the specification can be accessed from
outside of the
package. Such elements are known as a public element.
The package specification is a standalone element that means it can exist alone
without package
body.
SYNTAX :
-------
Package Body :
-------------
It consists of the definition of all the elements that are present in the package
specification. It
can also have a definition of elements that are not declared in the specification,
these elements
are called private elements and can be called only from inside the package.
The state of the package body becomes 'Invalid' whenever the specification is
compiled.
The private elements should be defined first before they are used in the package
body.
The first part of the package is the global declaration part. This includes
variables, cursors and
private elements (forward declaration) that is visible to the entire package.
The last part of the package is Package initialization part that executes one time
whenever a
package is referred first time in the session.
SYNTAX :
-------
Advantages :
------------
modularity
easier application design
information hiding
added functionality
better performance
Security
reusability
Disadvantages :
--------------
More Memory required on the oracle database server when using oracle PL/SQL
Packages as
the whole package is loaded into memory as soon as any object of the package is
accessed.
Updating one of the function/procedure will invalid other objects which use
different
function/procedure since whole package need to be compiled.