Package Theory
Package Theory
PL/SQL package is a group of related functions, procedures, types, cursors, etc. PL/SQL package is like a library
once written stored in the Oracle database and can be used by many applications. It is a schema object that
groups logically related PL/SQL types, variables, and subprograms
A PL/SQL package has two parts: package specification and package body.
A package specification is the public interface of the applications. The specification is the interface to the
package. It declares the types, variables, constants, exceptions, cursors, and subprograms that can be
referenced from outside the package. The public means the stored function, procedures, types, etc., are
accessible from other applications.
A package body contains the code that implements the package specification. The body defines the queries
for the cursors and the code for the subprograms.
Example:
PACKAGE BODY :
PACKAGE SPECIFICATION :
create or replace package body alloperation
create or replace package alloperation is
is procedure forinsert(rno number,sname varchar,crc
procedure forinsert(rno number,sname varchar,gen
varchar,crc varchar,gen varchar)
varchar); is
procedure forretrive(rno number); begin
insert into student values(rno,sname,crc,gen);
procedure forupdate(rno number,sname
end forinsert;
varchar); procedure forretrive(rno number)
procedure fordelete(rno number); is
end alloperation; sname student.student_name%type;
/ crc student.course%type;
Package created. gen student.gender%type;
begin
select student_name,course,gender into
sname,crc,gen
from student where roll_no=rno;
dbms_output.put_line(sname||' '||crc||' '||gen);
end forretrive;
procedure forupdate(rno number,sname varchar)
is
begin
update student set student_name=sname where
roll_no=rno;
end forupdate;
procedure fordelete(rno number)
is
begin
delete student where roll_no=rno;
end fordelete;
end alloperation;