0% found this document useful (0 votes)
32 views5 pages

Krishna Verma 3.2 Dbms

The document describes an experiment on implementing packages in Oracle Database 11g. It explains that packages in PL/SQL group logically related types, variables, and subprograms. A package has two mandatory parts - a specification that declares interfaces and a body that defines implementations. The experiment involves creating a customers table, a package to add, delete, and list customers, calling the package procedures, and output screenshots. The goal is to learn about packages, their specification and body, and syntax for creation.

Uploaded by

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

Krishna Verma 3.2 Dbms

The document describes an experiment on implementing packages in Oracle Database 11g. It explains that packages in PL/SQL group logically related types, variables, and subprograms. A package has two mandatory parts - a specification that declares interfaces and a body that defines implementations. The experiment involves creating a customers table, a package to add, delete, and list customers, calling the package procedures, and output screenshots. The goal is to learn about packages, their specification and body, and syntax for creation.

Uploaded by

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

DEPARTMENT OF

COMPUTER SCIENCE & ENGINEERING

EXPERIMENT No. 3.2

Student Name: Krishna verma UID: 21BCS10930


Branch: Computer Science & Engineering Section/Group: 804 B
Semester: 3rd Date of Performance: 11/11/22
Subject Name: Database Management System Subject Code: 21CSH-214

Aim of the practical:


Introduction and implementation of programs of Packages.

Software Requirements: Oracle Database 11g Express Edition

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.

Code & Output Screenshots:


CODE:
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

Create table customers (id number (10) not null,


name varchar(20) not null,
age number(12) not null,
salary number(8) not null,
address varchar(20) not null);
Desc customers;
Insert into customers values('22334', 'ashley', '34', '45000', 'banglore');
Insert into customers values('18778', 'emma', '56', '60000', 'hyderabad');
Insert into customers values('24313', 'richard', '29', '55000', 'lucknow');
Insert into customers values('18336', 'damien', '40', '50000', 'mumbai');
Select * from customers;

Create or replace package c_package as


-- adds a customer
Procedure addcustomer(c_id customers.id%type,
c_name customers.name%type,
c_age customers.age%type,
c_addr customers.address%type,
c_sal customers.salary%type);

-- removes a customer
Procedure delcustomer(c_id customers.id%type);

--lists all customers


Procedure listcustomer;
End c_package;
/

Create or replace package body c_package as


Procedure addcustomer(c_id customers.id%type,
c_name customers.name%type,
c_age customers.age%type,
c_addr customers.address%type,
c_sal customers.salary%type)
Is
Begin
Insert into customers (id,name,age,address,salary)
Values(c_id, c_name, c_age, c_addr, c_sal);
End addcustomer;

Procedure delcustomer(c_id customers.id%type) is


Begin
Delete from customers
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

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:

 Output Screenshot for Table Created:


DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

 Output Screenshot for Code written to implement Package :

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

You might also like