A package is a collection of related PL/SQL objects. The package contains a body and a specification. The package specification has the declaration which is public and can be used in the PL/SQL sub programs inside the package.
The package body holds the implementation of all the PL/SQL objects declared in the specification.
Example of a PL/SQL Package.
CREATE OR REPLACE PACKAGE emp_data AS
PROCEDURE add_employee (
ename VARCHAR2,
job VARCHAR2,
mgr NUMBER,
sal NUMBER,
deptno NUMBER);
END emp_actions;
CREATE OR REPLACE PACKAGE BODY emp_data AS
PROCEDURE add_employee (
ename VARCHAR2,
job VARCHAR2,
mgr NUMBER,
sal NUMBER,
deptno NUMBER) IS
BEGIN
INSERT INTO emp VALUES (empno_seq.NEXTVAL, ename, job, mgr, SYSDATE, comm, deptno);
END add_employee;
END emp_data;
Advantages of PL/SQL packages :
Packages are easier for application designing, encapsulating data, additional functionality and better performance. An application has various modules which can be placed in packages and handled easier.