0% found this document useful (0 votes)
11 views3 pages

Package

A PL/SQL package is a logical grouping of related subprograms that consists of a package specification and a package body. The specification declares public elements accessible from outside, while the body defines these elements and can include private elements. Packages offer advantages like modularity and security but may require more memory and can lead to invalidation of other objects when updated.

Uploaded by

shalih786
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views3 pages

Package

A PL/SQL package is a logical grouping of related subprograms that consists of a package specification and a package body. The specification declares public elements accessible from outside, while the body defines these elements and can include private elements. Packages offer advantages like modularity and security but may require more memory and can lead to invalidation of other objects when updated.

Uploaded by

shalih786
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

PACKAGES (Packaged or stored) :

PL/SQL package is a logical grouping of a related subprogram (procedure/function)


into a single
element.

A Package is compiled and stored as a database object that can be used later.

Components of Packages :
-----------------------

Package Specification
Package Body

Package Specification :
----------------------

Package specification consists of a declaration of all the public variables,


cursors, objects,
procedures, functions, and exception.

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 :
-------

CREATE [OR REPLACE] PACKAGE <package_name>


IS
<sub_program and public element declaration>
.
.
END <package name>

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.

Therefore, it needs to be recompiled each time after the compilation of


specification.

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 :
-------

CREATE [OR REPLACE] PACKAGE BODY <package_name>


IS
<global_declaration part>
<Private element definition>
<sub_program and public element definition>
.
<Package Initialization>
END <package_name>
Example Program :
create or replace package pkg_test
as
procedure proc_test;
v_test varchar2(50);
end pkg_test;
/

CREATE OR REPLACE PACKAGE BODY pkg_test


AS
procedure proc_test
is
begin
null;
end proc_test;
begin
dbms_output.put_line('test_complete'); ------one time procedure
end;
/
show err;
/

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.

You might also like