Krishna Verma 3.2 Dbms
Krishna Verma 3.2 Dbms
Introduction:
Packages are schema objects that groups logically related PL/SQL types, variables, and subprograms.
A package will have two mandatory parts –
a) Package specification
b) Package body or definition
PACKAGE SPECIFICATION: The specification is the interface to the package. It just DECLARES the
types, variables, constants, exceptions, cursors, and subprograms that can be referenced from outside
the package. In other words, it contains all information about the content of the package, but excludes
the code for the subprograms.
PACKAGE BODY/DEFINITION: The package body has the codes for various methods declared in the
package specification and other private declarations, which are hidden from the code outside the
package.
-- removes a customer
Procedure delcustomer(c_id customers.id%type);
Where id = c_id;
End delcustomer;
Procedure listcustomer is
Cursor c_customers is
Select name from customers;
Type c_list is table of customers.name%type;
Name_list c_list := c_list();
Counter integer :=0;
Begin
For n in c_customers loop
Counter := counter +1;
Name_list.extend;
Name_list(counter) := n.name;
Dbms_output.put_line('customer(' ||counter|| ')'||name_list(counter));
End loop;
End listcustomer;
End c_package;
/
Declare
Code customers.id%type:= 8;
Begin
C_package.addcustomer(7, 'rajnish', 25, 'chennai', 3500);
C_package.addcustomer(8, 'subham', 32, 'delhi', 7500);
C_package.listcustomer;
C_package.delcustomer(code);
C_package.listcustomer;
End;
/
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
OUTPUT SCREENSHOT:
Learning Outcomes:
1) Learnt what Packages in PL/SQL are
2) Learnt that a package consists of 2 compulsory parts: specification and body/definition
3) Learnt the syntax for creation of package