Upload
thiruvenkataprasad
View
281
Download
1
Embed Size (px)
Citation preview
8/2/2019 DBMS Lab Manual - 1
1/53
M.A.M. SCHOOL OF ENGINEERING, SIRUGANUR, TIRUCHIRAPPALLI 621105
DEPARTMENT OF C.S.E.
CS1256 - DBMS LAB MANUAL
Ex. No.1
STUDY OF DDL COMMANDS
AIM: To study the usage of various Data Definition Language commands
PROCEDURE:
1. CREATE TABLE2. ALTER TABLE
a. ADDb. MODIFY
3. TRUNCATE TABLE4. DROP TABLE
OUTPUT:
CREATE TABLE COMMAND
SQL>create table student(rollno number(2),name varchar2(20),dept varchar2(5),doj
date);
SQL> desc student;
Name Null? Type
----------------------------------------- -------- ----------------------------
ROLLNO NUMBER(2)
NAME VARCHAR2(20)
DEPT VARCHAR2(5)
DOJ DATE
ALTER TABLE COMMAND
ADD COMMAND
SQL> alter table student add regno number(10);
Table altered.
8/2/2019 DBMS Lab Manual - 1
2/53
M.A.M. SCHOOL OF ENGINEERING, SIRUGANUR, TIRUCHIRAPPALLI 621105
DEPARTMENT OF C.S.E.
CS1256 - DBMS LAB MANUAL
SQL> desc student;
Name Null? Type----------------------------------------- -------- ----------------------------
ROLLNO NUMBER(2)
NAME VARCHAR2(20)
DEPT VARCHAR2(5)
DOJ DATE
REGNO NUMBER(10)
MODIFY COMMAND
SQL> alter table student modify ( name varchar2(25));
Table altered.
SQL> desc student;
Name Null? Type
----------------------------------------- -------- ----------------------------
ROLLNO NUMBER(2)
NAME VARCHAR2(25)
DEPT VARCHAR2(5)
DOJ DATE
REGNO NUMBER(10)
TRUNCATE TABLE COMMAND
INSERTING DATA INTO TABLE:
SQL> insert into student values(1,'ajay','cse','15-aug-06',8082104001);
1 row created
SQL> insert into student values(1,'barathi',ece','20-july-06',8083104001);
1 row created
SQL> select * from student;
ROLLNO NAME DEPT DOJ REGNO
---------- ------------------------- ----- --------- ----------------------------------
1 ajay cse 15-AUG-06 8082104001
1 barathi ece 20-JUL-06 8083104001
SQL> truncate table student;
Table truncated.
8/2/2019 DBMS Lab Manual - 1
3/53
M.A.M. SCHOOL OF ENGINEERING, SIRUGANUR, TIRUCHIRAPPALLI 621105
DEPARTMENT OF C.S.E.
CS1256 - DBMS LAB MANUAL
SQL> select * from student;
no rows selected
SQL> desc student;
Name Null? Type
----------------------------------------- -------- ----------------------------
ROLLNO NUMBER(2)
NAME VARCHAR2(25)
DEPT VARCHAR2(5)
DOJ DATE
REGNO NUMBER(10)
DROP TABLE COMMAND
SQL> drop table student;
Table dropped.
SQL> desc student;
ERROR:
ORA-04043: object student does not exist
SQL> select * from student;
select * from student
*
ERROR at line 1:
ORA-00942: table or view does not exist
RESULT:
Thus the DDL commands are studied and executed.
Ex.No. 2STUDY OF DML COMMANDS
AIM: To study the usage of various Data Manipulation Language commands
PROCEDURE:
1.INSERT COMMAND
2.SELECT COMMAND
8/2/2019 DBMS Lab Manual - 1
4/53
M.A.M. SCHOOL OF ENGINEERING, SIRUGANUR, TIRUCHIRAPPALLI 621105
DEPARTMENT OF C.S.E.
CS1256 - DBMS LAB MANUAL
3.UPDATE COMMAND
4.DELETE COMMAND
OUTPUT:
CREATING A TABLE:
SQL> create table player(name varchar2(20), country varchar2(15),
matches number(3), goals number(2), jersey number(2));
Table created.
SQL> desc player;
Name Null? Type----------------------------------------- -------- ------------------
---
NAME VARCHAR2(20)
COUNTRY VARCHAR2(15)
MATCHES NUMBER(3)
GOALS NUMBER(2)
JERSEY NUMBER(2)
INSERT COMMAND
SQL> insert into player values('Ronaldo', 'Brazil', 85, 45, 9);
1 row created.
SQL> insert into player values('&name', '&country', &matches, &goals,
&jersey);
Enter value for name: Zidane
Enter value for country: France
Enter value for matches: 110
Enter value for goals: 34
Enter value for jersey: 10
old 1: insert into player values('&name', '&country', &matches,
&goals, &jersey)new 1: insert into player values('Zidane', 'France', 110, 34, 10)
1 row created.
SQL> /
Enter value for name: Figo
Enter value for country: Portugal
Enter value for matches: 102
Enter value for goals: 30
Enter value for jersey: 7
old 1: insert into player values('&name', '&country', &matches,
&goals, &jersey)
new 1: insert into player values('Figo', 'Portugal', 102, 30, 7)
1 row created.
8/2/2019 DBMS Lab Manual - 1
5/53
M.A.M. SCHOOL OF ENGINEERING, SIRUGANUR, TIRUCHIRAPPALLI 621105
DEPARTMENT OF C.S.E.
CS1256 - DBMS LAB MANUAL
SQL> insert into player(name, country,matches) values('Lehmann',
'Germany', 60);
1 row created.
SQL> insert into player values('Barthez', 'France', 95, null, null);
1 row created.
SELECT COMMAND
SQL> select * from player;
NAME COUNTRY MATCHES GOALS JERSEY
-------------------- --------------- ---------- ---------- ----------
Ronaldo Brazil 85 45 9
Zidane France 110 34 10
Figo Portugal 102 30 7
Lehmann Germany 60
Barthez France 95
SQL> select name, country from player;
NAME COUNTRY
-------------------- ---------------Ronaldo Brazil
Zidane France
Figo Portugal
Lehmann Germany
Barthez France
SQL> select distinct country from player;
COUNTRY
---------------
Brazil
FranceGermany
Portugal
SQL> select * from player where matches>=100;
NAME COUNTRY MATCHES GOALS JERSEY
-------------------- --------------- ---------- ---------- ----------
Zidane France 110 34 10
Figo Portugal 102 30 7
SQL> select * from player order by matches;
NAME COUNTRY MATCHES GOALS JERSEY
8/2/2019 DBMS Lab Manual - 1
6/53
M.A.M. SCHOOL OF ENGINEERING, SIRUGANUR, TIRUCHIRAPPALLI 621105
DEPARTMENT OF C.S.E.
CS1256 - DBMS LAB MANUAL
-------------------- --------------- ---------- ---------- ----------
Lehmann Germany 60
Ronaldo Brazil 85 45 9
Barthez France 95
Figo Portugal 102 30 7
Zidane France 110 34 10
SQL> select * from player order by matches desc;
NAME COUNTRY MATCHES GOALS JERSEY
-------------------- --------------- ---------- ---------- ----------
Zidane France 110 34 10
Figo Portugal 102 30 7
Barthez France 95
Ronaldo Brazil 85 45 9
Lehmann Germany 60
SQL> select * from player where name like 'F%';
NAME COUNTRY MATCHES GOALS JERSEY
-------------------- --------------- ---------- ---------- ----------
Figo Portugal 102 30 7
SQL> select * from player where name like 'Z____e';
NAME COUNTRY MATCHES GOALS JERSEY-------------------- --------------- ---------- ---------- ----------
Zidane France 110 34 10
SQL> select name player , country nation from player;
PLAYER NATION
-------------------- ---------------
Lehmann Germany
Barthez France
Ronaldo Brazil
Zidane France
Figo Portugal
UPDATE COMMAND
SQL> update player set jersey=1 where goals is null;
2 rows updated.
SQL> select * from player;
NAME COUNTRY MATCHES GOALS JERSEY
-------------------- --------------- ---------- ---------- ----------
Ronaldo Brazil 85 45 9Zidane France 110 34 10
Figo Portugal 102 30 7
8/2/2019 DBMS Lab Manual - 1
7/53
M.A.M. SCHOOL OF ENGINEERING, SIRUGANUR, TIRUCHIRAPPALLI 621105
DEPARTMENT OF C.S.E.
CS1256 - DBMS LAB MANUAL
Lehmann Germany 60 1
Barthez France 95 1
DELETE COMMAND:
SQL> delete from player where jersey=1;
2 rows deleted.
SQL> select * from player;
NAME COUNTRY MATCHES GOALS JERSEY
-------------------- --------------- ---------- ---------- ----------
Ronaldo Brazil 85 45 9
Zidane France 110 34 10
Figo Portugal 102 30 7
SQL> delete from player;
3 rows deleted.
SQL> select * from player;
no rows selected
RESULT:
Thus the DML commands are studied and executed.
Ex.No.3
STUDY OF DCL COMMANDS
Aim: To study the usage of various Data Control Language commands.
Procedure:
Grant command: To grant privileges on a particular table to
another user;
Revoke command: To revoke privileges on a particular table
from another user;
Output:
System:
SQL> create table employee(name varchar2(20), empnumber number(8),
designation varchar2(20), salary
number(6));
Table created.
SQL> desc employee;
Name Null? Type
8/2/2019 DBMS Lab Manual - 1
8/53
M.A.M. SCHOOL OF ENGINEERING, SIRUGANUR, TIRUCHIRAPPALLI 621105
DEPARTMENT OF C.S.E.
CS1256 - DBMS LAB MANUAL
----------------------------------------- -------- ------------------
- NAME
VARCHAR2(20)
EMPNUMBER NUMBER(8)
DESIGNATION VARCHAR2(20)
SALARY NUMBER(6)
SQL> insert into employee values('&name', &empnumber, '&designation',
&salary);
Enter value for name: Raja
Enter value for empnumber: 12345
Enter value for designation: Manager
Enter value for salary: 22000
old 1: insert into employee values('&name', &empnumber,
'&designation', &salary)
new 1: insert into employee values('Raja', 12345, 'Manager', 22000)
1 row created.
SQL> /
Enter value for name: Rajesh
Enter value for empnumber: 12678
Enter value for designation: Programmer Trainee
Enter value for salary: 7000
old 1: insert into employee values('&name', &empnumber,
'&designation', &salary)
new 1: insert into employee values('Rajesh', 12678, 'Programmer
Trainee', 7000)
1 row created.
SQL> /
Enter value for name: Shankar
Enter value for empnumber: 12367
Enter value for designation: Team Leader
Enter value for salary: 15000
old 1: insert into employee values('&name', &empnumber,
'&designation', &salary)
new 1: insert into employee values('Shankar', 12367, 'Team Leader',
15000)
1 row created.
SQL> /
Enter value for name: Tamilselvan
Enter value for empnumber: 25467
Enter value for designation: Programmer
Enter value for salary: 10000
old 1: insert into employee values('&name', &empnumber,
'&designation', &salary)
new 1: insert into employee values('Tamilselvan', 25467,
'Programmer', 10000)
1 row created.
SQL> grant select,update on employee to system1;
Grant succeeded.
8/2/2019 DBMS Lab Manual - 1
9/53
M.A.M. SCHOOL OF ENGINEERING, SIRUGANUR, TIRUCHIRAPPALLI 621105
DEPARTMENT OF C.S.E.
CS1256 - DBMS LAB MANUAL
System1:
SQL> select * from system.employee;
NAME EMPNUMBER DESIGNATION SALARY
-------------------- ---------- -------------------- ----------
Raja 12345 Manager 22000
Rajesh 12678 Programmer Trainee 7000
Shankar 12367 Team Leader 15000
Tamilselvan 25467 Programmer 10000
SQL> update system.employee set salary=8000 where empnumber=12678;
1 row updated.
SQL> select * from system.employee;
NAME EMPNUMBER DESIGNATION SALARY
-------------------- ---------- -------------------- ----------
Raja 12345 Manager 22000
Rajesh 12678 Programmer Trainee 8000
Shankar 12367 Team Leader 15000
Tamilselvan 25467 Programmer 10000
System:
SQL> grant ALL on employee to system1;
Grant succeeded.
System1:
SQL> insert into system.employee values('Naveen', 34521, 'Program
Manager', 20000);
1 row created.
SQL> select * from system.employee;
NAME EMPNUMBER DESIGNATION SALARY
-------------------- ---------- -------------------- ----------
Raja 12345 Manager 22000
Rajesh 12678 Programmer Trainee 8000
Shankar 12367 Team Leader 15000
Tamilselvan 25467 Programmer 10000
Naveen 34521 Program Manager 20000
System:
SQL> grant ALL on employee to system1 with grant option;
Grant succeeded.
8/2/2019 DBMS Lab Manual - 1
10/53
M.A.M. SCHOOL OF ENGINEERING, SIRUGANUR, TIRUCHIRAPPALLI 621105
DEPARTMENT OF C.S.E.
CS1256 - DBMS LAB MANUAL
System1:
SQL> grant ALL on system.employee to system2;
Grant succeeded.
System2:
SQL> update system.employee set salary=8500 where empnumber=12678;
1 row updated.
SQL> select * from system.employee;
NAME EMPNUMBER DESIGNATION SALARY
-------------------- ---------- -------------------- ----------
Raja 12345 Manager 22000Rajesh 12678 Programmer Trainee 8500
Shankar 12367 Team Leader 15000
Tamilselvan 25467 Programmer 10000
Naveen 34521 Program Manager 20000
System1:
SQL> revoke all on system.employee from system2;
Revoke succeeded.
System2:
SQL> select * from system.employee;
select * from system.employee
*
ERROR at line 1:
ORA-00942: table or view does not exist
System1:
SQL> select * from system.employee;
NAME EMPNUMBER DESIGNATION SALARY
-------------------- ---------- -------------------- ----------
Raja 12345 Manager 22000Rajesh 12678 Programmer Trainee 8500
Shankar 12367 Team Leader 15000
Tamilselvan 25467 Programmer 10000
Naveen 34521 Program Manager 20000
System:
SQL> revoke update on employee from system1;
Revoke succeeded.
System1:
SQL> update system.employee set name='Rajesh Kumar' whereempnumber=12678;
update system.employee set name='Rajesh Kumar' where empnumber=12678
8/2/2019 DBMS Lab Manual - 1
11/53
M.A.M. SCHOOL OF ENGINEERING, SIRUGANUR, TIRUCHIRAPPALLI 621105
DEPARTMENT OF C.S.E.
CS1256 - DBMS LAB MANUAL
*
ERROR at line 1:
ORA-01031: insufficient privileges
SQL> select * from system.employee;
NAME EMPNUMBER DESIGNATION SALARY
-------------------- ---------- -------------------- ----------
Raja 12345 Manager 22000
Rajesh 12678 Programmer Trainee 8500
Shankar 12367 Team Leader 15000
Tamilselvan 25467 Programmer 10000
Naveen 34521 Program Manager 20000
System:
SQL> select * from employee;
NAME EMPNUMBER DESIGNATION SALARY
-------------------- ---------- -------------------- ----------
Raja 12345 Manager 22000
Rajesh 12678 Programmer Trainee 8500
Shankar 12367 Team Leader 15000
Tamilselvan 25467 Programmer 10000
Naveen 34521 Program Manager 20000
Result: Thus the DCL commands are studied and executed.
Ex.No: 4
Procedures
AIM:
To study the usage of procedures in SQL commands.
PROCEDURE:
1. Insert Procedure Command2. Select Procedure Command3. Delete Procedure Command4.
Update Procedure Command
OUTPUT:
SQL>create table inventory(pcode varcar2(10),pname varcahr2(25),pqty
number(3),pprice number(5));
Table created
SQL> desc inventory;
Name Null? Type----------------------------------------- -------- ----------------------------
8/2/2019 DBMS Lab Manual - 1
12/53
M.A.M. SCHOOL OF ENGINEERING, SIRUGANUR, TIRUCHIRAPPALLI 621105
DEPARTMENT OF C.S.E.
CS1256 - DBMS LAB MANUAL
PCODE VARCHAR2(10)
PNAME VARCHAR2(25)
PQTY NUMBER(3)PPRICE NUMBER(5).
SQL>ed ex1
create procedure pro_insert(x1 varchar,x2 varchar,x3 number,x4 number) as
procode varchar2(20);
proname varchar2(20);
pqty number(20);
pprice number(20);
begin
procode :=x1;
proname :=x2;
pqty :=x3;
pprice :=x4;
insert into inventory values(procode,proname,pqty,pprice);
end;
SQL> @ ex1;
15 /
Procedure created.
SQL> exec pro_insert('p1','Book',50,10);
PL/SQL procedure successfully completed.
SQL> exec pro_insert('p2','pen',60,20);
PL/SQL procedure successfully completed.
SQL> exec pro_insert('p3','book',30,50);
PL/SQL procedure successfully completed.
8/2/2019 DBMS Lab Manual - 1
13/53
M.A.M. SCHOOL OF ENGINEERING, SIRUGANUR, TIRUCHIRAPPALLI 621105
DEPARTMENT OF C.S.E.
CS1256 - DBMS LAB MANUAL
SQL> select * from inventory;
PCODE PNAME QTY PPRICE---------- ------------------------- -------- ----------
p1 pencil 50 10
p2 pen 60 20
p3 book 30 50
SQL> ed ex2;
create procedure pro_del(x1 varchar) as
procode varchar2(20);
begin
procode :=x1;
delete from inventory where pcode=procode;
dbms_output.put_line('Record deleted');
end;
SQL> @ ex2;
10 /
Procedure created.
SQL> exec pro_del('p3');
PL/SQL procedure successfully completed.
SQL> select * from inventory;
PCODE PNAME PQTY PPRICE
---------- ------------------------- ---------- ----------
p1 pencil 50 10
p2 pen 60 20
SQL> ed ex3;
8/2/2019 DBMS Lab Manual - 1
14/53
M.A.M. SCHOOL OF ENGINEERING, SIRUGANUR, TIRUCHIRAPPALLI 621105
DEPARTMENT OF C.S.E.
CS1256 - DBMS LAB MANUAL
create procedure pro_update(x1 varchar, x2 number)as
tpcode varchar2(10);tqty number(10);
tpqty number(10);
begin
tpcode:=x1;
tqty:=x2;
select tqty into tpqty from inventory where pcode = tpcode;
if SQL%FOUND Then
update inventory set pqty = tpqty where pcode=tpcode;
dbms_output.put_line('Record updated successfully');
else
dbms_output.put_line('No record found');end if;
end;
SQL> @ ex3;
22 /
Procedure created.
SQL> exec pro_update('p1',100);
PL/SQL procedure successfully completed.
SQL> select * from inventory;
PCODE PNAME PQTY PPRICE
---------- ------------------------- ---------- ----------
p1 pencil 100 10
p2 pen 60 20
RESULT:
Thus the procedure to insert, update and delete the inventory was create and
executed
FUNCTIONS
Ex.No: 5
AIM:
8/2/2019 DBMS Lab Manual - 1
15/53
M.A.M. SCHOOL OF ENGINEERING, SIRUGANUR, TIRUCHIRAPPALLI 621105
DEPARTMENT OF C.S.E.
CS1256 - DBMS LAB MANUAL
Write a PL/SQL using function to check the inventory
level.
PROCEDURE:
1.Create the table- product2.Insert the values3.Create the PL/SQL function4.Run the function in the SQL prompt
OUTPUT:
SQL> create table product( pcode varchar2(3),pname
varchar2(10),qty_hand number(3),qty_min(3));
Table Created
SQL> desc product;
Name Null? Type
----------------------------------------- -------- -------
PCODE VARCHAR2(3)
PNAME VARCHAR2(10)
QTY_HAND NUMBER(3)
QTY_MIN NUMBER(3)
SQL> insert into product values ('RC','Rice', 85,100);
1 row created.
SQL> insert into product values ('SG','Sugar', 50,50);
1 row created.
SQL> insert into product values ('WH','Wheat, 200,100);
1 row created.
SQL> select * from product;
PCO PNAME QTY_HAND QTY_MIN
--- ---------- ---------- ----------
RC Rice 85 100
SG Sugar 50 50
WH Wheat 200 100
REORDER FUNCTION
FUN.SQL
create or replace function reorder_fun(code varchar2)return number is
reorderqty number;
8/2/2019 DBMS Lab Manual - 1
16/53
M.A.M. SCHOOL OF ENGINEERING, SIRUGANUR, TIRUCHIRAPPALLI 621105
DEPARTMENT OF C.S.E.
CS1256 - DBMS LAB MANUAL
minqty number;
handqty number;
beginselect qty_hand, qty_min into handqty, minqty from product where
pcode=code;
if handqty < minqty then
reorderqty:=minqty-handqty;
return reorderqty;
else
reorderqty:=0;
return reorderqty;
end if;
end;
-----------------------------------------------------------------
SQL> @ fun;
16 /
Function created.
----------------------------------------------------------------
-
SQL>set serveroutput on;
----------------------------------------------------------------
-
SQL> declare
2 a varchar2(5);
3 b number;
4 begin
5 a:=&a;
6 b:=reorder_fun(a);
7 dbms_output.put_line('QTY TO BE ORDERED IS :'|| b);
8 end;
9 /Enter value for a: 'RC'
old 5: a:=&a;
new 5: a:='RC';
QTY TO BE ORDERED IS :15
PL/SQL procedure successfully completed.
-----------------------------------------------------------
SQL> declare
2 a varchar2(5);3 b number;
4 begin
8/2/2019 DBMS Lab Manual - 1
17/53
M.A.M. SCHOOL OF ENGINEERING, SIRUGANUR, TIRUCHIRAPPALLI 621105
DEPARTMENT OF C.S.E.
CS1256 - DBMS LAB MANUAL
5 a:=&a;
6 b:=reorder_fun(a);
7 dbms_output.put_line('QTY TO BE ORDERED IS :'|| b);8 end;
9 /
Enter value for a: 'SG'
old 5: a:=&a;
new 5: a:='SG';
QTY TO BE ORDERED IS :0
PL/SQL procedure successfully completed.
Result:
Thus the PL/SQL function to check the inventory was
created and executed.
HIGH LEVEL LANGUAGE EXTENSION WITH TRIGGERS
Ex.No: 6
AIM:
Write a Trigger program to maintain the inventory level
PROCEDURE:
1. Create Table stock.2. Create procedure for inserting values into the table.3. Insert the values into the table4. Create Procedure for updating the table.5. Create a trigger point to catch the illegal entry.6. Update the table using update procedure.
OUTPUT:
SQL> create table stock(pcode varchar2(3),pname varchar2(10),qty_hand
number(4),qty_sales number(4));
Table created.
SQL> desc stock;
Name Null? Type
----------------------------------------- -------- ------------------
-
PCODE VARCHAR2(3)
PNAME VARCHAR2(10)
QTY_HAND NUMBER(4)
QTY_SALES NUMBER(4)
----------------------------------------------------------------------
SQL> ed t1;-----------------------------------------------------------------------
8/2/2019 DBMS Lab Manual - 1
18/53
M.A.M. SCHOOL OF ENGINEERING, SIRUGANUR, TIRUCHIRAPPALLI 621105
DEPARTMENT OF C.S.E.
CS1256 - DBMS LAB MANUAL
create procedure stock_insert(x1 varchar,x2 varchar,x3 number, x4
number) as
procode varchar2(20);
proname varchar2(20);
pqty number(20);
psales number(20);
begin
procode :=x1;
proname :=x2;
pqty :=x3;
psales :=x4;
insert into stock values(procode,proname,pqty,psales);
end;
-------------------------------------------------- --------------------
-
SQL> @ t1;
13 /
Procedure created.
----------------------------------------------------------------------
-
SQL> exec stock_insert('p1','oil',5000,0);
PL/SQL procedure successfully completed.
SQL> exec stock_insert('p2','soap',7000,0);
PL/SQL procedure successfully completed.
SQL> exec stock_insert('p3','powder',4000,0);
PL/SQL procedure successfully completed.
----------------------------------------------------------------------
-
SQL> select * from stock;
PCO PNAME QTY_HAND QTY_SALES--- ---------- ---------- ----------
p1 oil 5000 0
p2 soap 7000 0
p3 powder 4000 0
----------------------------------------------------------------------
-
SQL> ed t2;
----------------------------------------------------------------------
-
create procedure stock_upd(x1 varchar, x4 number) as
tqty number(20);thand number(20);
begin
8/2/2019 DBMS Lab Manual - 1
19/53
M.A.M. SCHOOL OF ENGINEERING, SIRUGANUR, TIRUCHIRAPPALLI 621105
DEPARTMENT OF C.S.E.
CS1256 - DBMS LAB MANUAL
select qty_hand,qty_sales into thand,tqty from stock where pcode = x1;
if SQL%FOUND Then
update stock set qty_hand = thand-x4 where pcode= x1;
update stock set qty_sales = tqty+x4 where pcode= x1;
end if;
end;
----------------------------------------------------------------------
-
SQL> @ t2;
9 /
Procedure created.
-------------------------------------------------- --------------------
-SQL>create or replace trigger tr1
2 before update on stock for each row
3 begin
4 if :new.qty_sales > :old.qty_hand then
5 raise_application_error (-20001,Quantity is Less);
6 end if;
7 end;
8 /
Trigger Created.
----------------------------------------------------------------------
-
SQL> exec stock_upd('p1',1000);
PL/SQL procedure successfully completed.
SQL> select * from stock;
PCO PNAME QTY_HAND QTY_SALES
--- ---------- ---------- ----------
p1 oil 4000 1000
p2 soap 7000 0
p3 powder 4000 0
SQL> exec stock_upd('p1',5000);
BEGIN stock_upd('p1',5000); END;
*
ERROR at line 1:
ORA-20001: Quantity is Less
ORA-06512: at "SYSTEM.TR1", line 3
ORA-04088: error during execution of trigger 'SYSTEM.TR1'
ORA-06512: at "SYSTEM.STOCK_UPD", line 9
ORA-06512: at line 1
----------------------------------------------------------------------
-
SQL> exec stock_upd('p1',900);
8/2/2019 DBMS Lab Manual - 1
20/53
M.A.M. SCHOOL OF ENGINEERING, SIRUGANUR, TIRUCHIRAPPALLI 621105
DEPARTMENT OF C.S.E.
CS1256 - DBMS LAB MANUAL
PL/SQL procedure successfully completed.
SQL> select * from stock;
PCO PNAME QTY_HAND QTY_SALES
--- ---------- ---------- ----------
p1 oil 3100 1900
p2 soap 7000 0
p3 powder 4000 0
----------------------------------------------------------------------
-
Result: Thus the trigger was written and executed in SQL Plus.
HIGH LEVEL LANGUAGE EXTENSION WITH CURSORS
Ex.No: 7
AIM:
Write a Cursor program to perform payroll processing.
PROCEDURE:
1. Create the employee, attendance table.2. Enter the values into the tables3. Create the table salary, into which the payroll process
is to be executed.
4. Declare a cursor to fetch values from employee table.5. Select the workdays, months, years from attendance
table for each employee number in the employee table.
6. Calculate the salary for each employee and insert it inthe salary table
OUTPUT:
SQL> create table employee(eno number(4),ename varchar2(20),esal
number(7,2),egrade varchar2(1));
Table created.
SQL> desc employee;
Name Null? Type
----------------------------------------- -------- ------------------
-
ENO NUMBER(4)
ENAME VARCHAR2(20)
ESAL NUMBER(7,2)
EGRADE VARCHAR2(1)
SQL> create table attendance(eno number(4),workdays number(2),monthsnumber(2),years number(4));
8/2/2019 DBMS Lab Manual - 1
21/53
M.A.M. SCHOOL OF ENGINEERING, SIRUGANUR, TIRUCHIRAPPALLI 621105
DEPARTMENT OF C.S.E.
CS1256 - DBMS LAB MANUAL
Table created.
SQL> desc attendance;
Name Null? Type
----------------------------------------- -------- --------------
ENO NUMBER(4)
WORKDAYS NUMBER(2)
MONTHS NUMBER(2)
YEARS NUMBER(4)
SQL> create table salary( eno number(4),ename varchar2(20), egrade
varchar2(1),netsal number(7,2),workdays number(2),
months number(2),years number(4));
Table created.
SQL> desc salary;
Name Null? Type
----------------------------------------- -------- ------------------
-
ENO NUMBER(4)
ENAME VARCHAR2(20)
EGRADE VARCHAR2(1)
NETSAL NUMBER(7,2)
WORKDAYS NUMBER(2)MONTHS NUMBER(2)
YEARS NUMBER(4)
SQL> insert into employee values(1,'Sham',10000,'C');
1 row created.
SQL> insert into employee values(2,'Raju',9000,'D');
1 row created.
SQL> insert into employee values(3,'Anish',15000,'A');
1 row created.
SQL> select * from employee;
ENO ENAME ESAL EGRADE
---------- -------------------- ---------- ------
1 Sham 10000 C
2 Raju 9000 D
3 Anish 15000 A
SQL> insert into attendance values(1,28,8,2006);
1 row created.
8/2/2019 DBMS Lab Manual - 1
22/53
M.A.M. SCHOOL OF ENGINEERING, SIRUGANUR, TIRUCHIRAPPALLI 621105
DEPARTMENT OF C.S.E.
CS1256 - DBMS LAB MANUAL
SQL> insert into attendance values(2,24,8,2006);
1 row created.
SQL> insert into attendance values(3,21,8,2006);
1 row created.
SQL> select * from attendance;
ENO WORKDAYS MONTHS YEARS
---------- ---------- ---------- ----------
1 28 8 2006
2 24 8 2006
3 21 8 2006
SQL> declare cursor emp is
2 select eno,ename,esal,egrade from employee;
3 empname varchar2(20);
4 empno number(4):=0;
5 empsal number(7,2):=0;
6 empgrade varchar2(1);7 netsalary number(7,2):=0;
8 wd number(2):=0;
9 m number(2):=0;
10 y number(4):=0;
11
12 begin
13 open emp ;
14
15 loop
16
17 fetch emp into empno,empname,empsal,empgrade;
18 exit when emp%notfound;
19 select workdays,months,years into wd,m,y from attendance whereeno=empno;
20 netsalary :=(empsal/30)* wd;
20 insert into salaryvalues(empno,empname,empgrade,netsalary,wd,m,y);
22
23 end loop;
24
25 close emp;
26 commit;
27 end;
28 /
PL/SQL procedure successfully completed.
SQL> select * from salary;
8/2/2019 DBMS Lab Manual - 1
23/53
M.A.M. SCHOOL OF ENGINEERING, SIRUGANUR, TIRUCHIRAPPALLI 621105
DEPARTMENT OF C.S.E.
CS1256 - DBMS LAB MANUAL
ENO ENAME EGRADE NETSAL WORKDAYS MONTHS
YEARS
---- -------------------- - ---------- ---------- ---------- ---------
-
1 Sham C 9333.33 28 8
2006
2 Raju D 7200 24 8
2006
3 Anish A 10500 21 8
2006
Result:
Thus the cursor was implemented to perform the payroll
process.
Ex.No.8
EMBEDED SQL
Aim:To write a java program for storing data in Oracle
Procedure:
i) Create a table with necessary fields.ii) Write a java program to receive input through forms.iii) Compile and execute the java program
OUTPUT:
SQL> desc student;
Name Null? Type
----------------------------------------- -------- -----------------
REGNO NUMBER(10)
NAME VARCHAR2(15)DEPT VARCHAR2(5)
BATCH VARCHAR2(10)
Program:
/* Program for Jdbc Connectivity*/
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;import java.sql.*;
8/2/2019 DBMS Lab Manual - 1
24/53
M.A.M. SCHOOL OF ENGINEERING, SIRUGANUR, TIRUCHIRAPPALLI 621105
DEPARTMENT OF C.S.E.
CS1256 - DBMS LAB MANUAL
public class stu extends JFrame
{JTextField tf1,tf2,tf3,tf4;
stu(String title)
{
Container con=(JPanel) getContentPane();
con.setLayout(null);
setSize(800,500);
setVisible(true);
JLabel l1=new JLabel("STUDENT INFORMATION");
JLabel l2=new JLabel("Regno");
JLabel l3=new JLabel("Name");JLabel l4=new JLabel("Dept");
JLabel l5=new JLabel("Batch");
tf1=new JTextField(10);
tf2=new JTextField(10);
tf3=new JTextField(10);
tf4=new JTextField(10);
con.add(l1);
con.add(l2);
con.add(l3);con.add(l4);
con.add(l5);
con.add(tf1);
con.add(tf2);
con.add(tf3);
con.add(tf4);
l1.setBounds(250,100,300,25);
l2.setBounds(100,150,100,25);
l3.setBounds(100,200,100,25);
l4.setBounds(100,250,100,25);
l5.setBounds(100,300,100,25);
tf1.setBounds(250,150,100,25);
tf2.setBounds(250,200,100,25);
tf3.setBounds(250,250,100,25);
tf4.setBounds(250,300,100,25);
JButton b1 = new JButton("Addnew");
JButton b2 = new JButton("Save");
JButton b3 = new JButton("Find");JButton b4 = new JButton("Update");
JButton b5 = new JButton("Delete");
8/2/2019 DBMS Lab Manual - 1
25/53
M.A.M. SCHOOL OF ENGINEERING, SIRUGANUR, TIRUCHIRAPPALLI 621105
DEPARTMENT OF C.S.E.
CS1256 - DBMS LAB MANUAL
con.add(b1);
con.add(b2);con.add(b3);
con.add(b4);
con.add(b5);
b1.setBounds(100,400,100,25);
b2.setBounds(200,400,100,25);
b3.setBounds(300,400,100,25);
b4.setBounds(400,400,100,25);
b5.setBounds(500,400,100,25);
b1.addActionListener(new A());
b2.addActionListener(new B());b3.addActionListener(new C());
b4.addActionListener(new D());
b5.addActionListener(new E());
addWindowListener(new w());
}
class w extends WindowAdapter
{
public void windowClosing(WindowEvent we){
System.exit(0);}
}
class A implements ActionListener
{
public void actionPerformed(ActionEvent ae)
{
tf1.setText("");
tf2.setText("");
tf3.setText("");
tf4.setText("");
}
}
class B implements ActionListener
{
public void actionPerformed(ActionEvent ae)
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con1=DriverManager.getConnection("jdbc:odbc:jcet","system","manager");
PreparedStatement pst=con1.prepareStatement("insert into student values(?,?,?,?)");int x1=Integer.parseInt(tf1.getText());
String x2=tf2.getText();
8/2/2019 DBMS Lab Manual - 1
26/53
M.A.M. SCHOOL OF ENGINEERING, SIRUGANUR, TIRUCHIRAPPALLI 621105
DEPARTMENT OF C.S.E.
CS1256 - DBMS LAB MANUAL
String x3=tf3.getText();
String x4=tf4.getText();
pst.setInt(1,x1);
pst.setString(2,x2);
pst.setString(3,x3);
pst.setString(4,x4);
int temp=pst.executeUpdate();
if(temp>0)
{
System.out.println("Record inserted");
}
}
catch(Exception ie){
System.out.println(ie.getMessage());
}
}
}
class C implements ActionListener
{
public void actionPerformed(ActionEvent ae)
{
try
{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con1=DriverManager.getConnection("jdbc:odbc:jcet","system","manager");
Statement st=con1.createStatement();
JFrame f= new JFrame();
int x = Integer.parseInt(JOptionPane.showInputDialog(f,"Enter the Register no"));
String qry="select * from student where regno="+x;
ResultSet rs=st.executeQuery(qry);
while(rs.next())
{
tf1.setText(String.valueOf(rs.getInt("regno")));
tf2.setText(rs.getString("name"));
tf3.setText(rs.getString("dept"));
tf4.setText(rs.getString("batch"));
}
}
catch(Exception ie)
{
System.out.println(ie.getMessage());
}
}
}
class D implements ActionListener{
public void actionPerformed(ActionEvent ae)
8/2/2019 DBMS Lab Manual - 1
27/53
M.A.M. SCHOOL OF ENGINEERING, SIRUGANUR, TIRUCHIRAPPALLI 621105
DEPARTMENT OF C.S.E.
CS1256 - DBMS LAB MANUAL
{
try
{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con1=DriverManager.getConnection("jdbc:odbc:jcet","system","manager");
int x =Integer.parseInt(tf1.getText());
String qry="update student set regno=?,name=?,dept=? , branch=? where regno="+x;
PreparedStatement pst=con1.prepareStatement(qry);
String x2=tf2.getText();
String x3=tf3.getText();
String x4=tf4.getText();
pst.setInt(1,x);
pst.setString(2,x2);pst.setString(3,x3);
pst.setString(4,x4);
int temp=pst.executeUpdate();
if(temp>0)
{
JFrame f = new JFrame();
JOptionPane.showMessageDialog(f,"Record Updated");
}
}
catch(Exception ie)
{
System.out.println(ie.getMessage());
}
}
}
class E implements ActionListener
{
public void actionPerformed(ActionEvent ae)
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con1=DriverManager.getConnection("jdbc:odbc:jcet","system","manager");
int x = Integer.parseInt(tf1.getText());
String qry="delete from student where regno="+x;
PreparedStatement pst = con1.prepareStatement(qry);
JFrame f= new JFrame();
int temp = pst.executeUpdate();
if (temp > 0 ){
8/2/2019 DBMS Lab Manual - 1
28/53
M.A.M. SCHOOL OF ENGINEERING, SIRUGANUR, TIRUCHIRAPPALLI 621105
DEPARTMENT OF C.S.E.
CS1256 - DBMS LAB MANUAL
tf1.setText("");
tf2.setText("");
tf3.setText("");tf4.setText("");
JOptionPane.showMessageDialog(f,"Record Deleted");
}
else
{
JOptionPane.showMessageDialog(f,"Record Not Found");
}
}
catch(Exception ie)
{
System.out.println(ie.getMessage());
}}
}
public static void main(String arg[]) throws Exception
{
stu sd = new stu("STUDENT INFORMATION");
}
}
OUTPUT:
8/2/2019 DBMS Lab Manual - 1
29/53
M.A.M. SCHOOL OF ENGINEERING, SIRUGANUR, TIRUCHIRAPPALLI 621105
DEPARTMENT OF C.S.E.
CS1256 - DBMS LAB MANUAL
Result:
Thus a java program was written to store data in SQL and executed successfully.
EX NO-9
LIBRARY MANAGEMENT SYSTEM
Aim:
To develop a package for a library management system
Procedure:
1. Create the table for books.2. Create the table for students.3. Create the table for lending books.4. Create the procedure for lending books5. Create the procedure for returning books and simultaneously
removing from lending table.
OUTPUT:
SQL> create table books(book_no varchar2(6),book_name
varchar2(35),book_author varchar2(20));
Table created.
SQL> desc books;
Name Null? Type
8/2/2019 DBMS Lab Manual - 1
30/53
M.A.M. SCHOOL OF ENGINEERING, SIRUGANUR, TIRUCHIRAPPALLI 621105
DEPARTMENT OF C.S.E.
CS1256 - DBMS LAB MANUAL
------------------------------- -------- ----
BOOK_NO VARCHAR2(6)
BOOK_NAME VARCHAR2(35)
BOOK_AUTHOR VARCHAR2(20)
----------------------------------------------------------------
SQL> create table students(reg_no varchar2(12),stu_name
varchar2(25),dept varchar2(4),batch varchar2(9));
Table created.
SQL> desc students;
Name Null? Type
------------------------------- -------- ----
REG_NO VARCHAR2(12)
STU_NAME VARCHAR2(25)
DEPT VARCHAR2(4)BATCH VARCHAR2(9)
----------------------------------------------------------------
SQL> insert into books values('cse1','Programming in
C','Balagurusamy');
1 row created.
SQL> insert into books values('cse2','Programming in
C','Balagurusamy');
1 row created.
SQL> insert into books values('cse3','The Complete Reference-
Java','Patrik Nort
1 row created.
SQL> insert into books values('ece1','Eletron Devices','Ravi Kumar');
1 row created.
SQL> insert into books values('ece2','Communication
Enginnering','dheraj shah');
1 row created.
SQL> insert into books values('ece3','Communication
Enginnering','dheraj shah');
1 row created.
SQL> select * from books;
BOOK_N BOOK_NAME BOOK_AUTHOR
------ ----------------------------------- --------------------
cse1 Programming in C Balagurusamycse2 Programming in C Balagurusamy
cse3 The Complete Reference-Java Patrik Norton
8/2/2019 DBMS Lab Manual - 1
31/53
M.A.M. SCHOOL OF ENGINEERING, SIRUGANUR, TIRUCHIRAPPALLI 621105
DEPARTMENT OF C.S.E.
CS1256 - DBMS LAB MANUAL
ece1 Eletron Devices Ravi Kumar
ece2 Communication Enginnering dheraj shah
ece3 Communication Enginnering dheraj shah
6 rows selected.
----------------------------------------------------------------
SQL> insert into students values('8080410910','Ajay','CSE','2005-
2009');
1 row created.
SQL> insert into students values('8080410911','Banu','CSE','2004-
2008');
1 row created.
SQL> insert into students values('8080510911','Sreeja','ECE','2004-
2008');
1 row created.
SQL> insert into students values('8080510910','Ram','ECE','2005-
2009');
1 row created.
SQL> select * from students;
REG_NO STU_NAME DEPT BATCH
------------ ------------------------- ---- ---------
8080410910 Ajay CSE 2005-2009
8080410911 Banu CSE 2004-2008
8080510911 Sreeja ECE 2004-2008
8080510910 Ram ECE 2005-2009
4 rows selected.
----------------------------------------------------------------
SQL> create table lending(reg_no varchar2(12),stu_name
varchar2(25),book_no varchar2(6),book_name va
rchar2(35), ddate date);
Table created.
SQL> desc lending;
Name Null? Type
------------------------------- -------- ----
REG_NO VARCHAR2(12)
STU_NAME VARCHAR2(25)
BOOK_NO VARCHAR2(6)BOOK_NAME VARCHAR2(35)
DDATE DATE
8/2/2019 DBMS Lab Manual - 1
32/53
M.A.M. SCHOOL OF ENGINEERING, SIRUGANUR, TIRUCHIRAPPALLI 621105
DEPARTMENT OF C.S.E.
CS1256 - DBMS LAB MANUAL
----------------------------------------------------------------
sql>create procedure lend(x1 varchar, x2 varchar)as
2 reg varchar2(12);
3 bno varchar2(6);
4 sname varchar2(25);
5 bname varchar2(35);
6 begin
7 reg:=x1;
8 bno:=x2;
9 select stu_name into sname from students where reg_no = reg;
10 if SQL%FOUND Then
11 select book_name into bname from books where book_no = bno;
12 if SQL%FOUND Then
13 insert into lending values(reg,sname,bno,bname,sysdate);
14 dbms_output.put_line('Record updated successfully');15 else
16 dbms_output.put_line('No book found');
17 end if;
18 else
19 dbms_output.put_line('No student found');
20 end if;
21 end;
Procedure created.
----------------------------------------------------------------
SQL> exec lend('8080410910','cse1');
PL/SQL procedure successfully completed.
SQL> select * from lending;
REG_NO STU_NAME BOOK_N BOOK_NAME DDATE
------------ ------------------------ ------ ---------------- -------
8080410910 Ajay cse1 Programming in C 01-OCT-
06
SQL> create table returning(reg_no varchar2(12),stu_name varchar
varchar2(35), ddate date,rdate date);
Table created.
SQL> desc returning;
Name Null? Type
------------------------------- -------- ----
REG_NO VARCHAR2(12)
STU_NAME VARCHAR2(25)
BOOK_NO VARCHAR2(6)
BOOK_NAME VARCHAR2(35)
DDATE DATERDATE DATE
8/2/2019 DBMS Lab Manual - 1
33/53
M.A.M. SCHOOL OF ENGINEERING, SIRUGANUR, TIRUCHIRAPPALLI 621105
DEPARTMENT OF C.S.E.
CS1256 - DBMS LAB MANUAL
----------------------------------------------------------------
sql>create procedure returns(x1 varchar)as
2 bno varchar2(6);
3 reg varchar2(12);
4 sname varchar2(25);
5 bname varchar2(35);
6 deldate date;
7 begin
8 bno:=x1;
9 select reg_no ,stu_name ,book_name ,ddate into
10 reg,sname,bname,deldate from lending where book_no = bno;
11 if SQL%FOUND Then
12 insert into returning values(reg, sname,bno,bname,deldate,sysdate);
13 delete from lending where book_no=bno;
14 else
15 dbms_output.put_line('No book found');16 end if;
17 end;
/
Procedure created.
----------------------------------------------------------------
SQL> exec returns('cse1');
PL/SQL procedure successfully completed.
SQL> select * from lending;
no rows selected
SQL> select * from returning;
REG_NO STU_NAME BOOK_N BOOK_NAME DDATE RDATE
----------------------------------------------------------------
8080410910 Ajay cse1 Programming in C 01-OCT-06 01-OCT-06
Result :
Thus the procedure for library management system was written and
executed.
EX NO-10
BANKING MANAGEMENT SYSTEM
Aim:
To develop the package for the bank management
system.
Procedure:
6. Create the table for customer.
8/2/2019 DBMS Lab Manual - 1
34/53
M.A.M. SCHOOL OF ENGINEERING, SIRUGANUR, TIRUCHIRAPPALLI 621105
DEPARTMENT OF C.S.E.
CS1256 - DBMS LAB MANUAL
7. Create the table for transaction.8. Insert the values in the bankmaster table using procedure.9. Write the procedure to insert the values in the customer
transaction table trans.
OUPTPUT:
SQL> create table bankmaster( accno number(15),accname
varchar2(20),address varchar2(20),balance num
ber(10));
Table created.
SQL> desc bankmaster;
Name Null? Type
------------------------------- -------- ----
ACCNO NUMBER(15)
ACCNAME VARCHAR2(20)
ADDRESS VARCHAR2(20)
BALANCE NUMBER(10)
SQL> create table trans(accno number(15),accname
varchar2(20),transdate date, transtype varchar2(1),
amt number(10));
Table created.
SQL> desc trans;
Name Null? Type
------------------------------- -------- ----
ACCNO NUMBER(15)
ACCNAME VARCHAR2(20)
TRANSDATE DATE
TRANSTYPE VARCHAR2(1)
AMT NUMBER(10)
SQL> set serveroutput on;
SQL> ed b1;
create or replace procedure custadd(x1 number, x2 varchar,
x3 varchar, x4 number) as
acno number;
acname varchar2(20);
add varchar2(20);
8/2/2019 DBMS Lab Manual - 1
35/53
M.A.M. SCHOOL OF ENGINEERING, SIRUGANUR, TIRUCHIRAPPALLI 621105
DEPARTMENT OF C.S.E.
CS1256 - DBMS LAB MANUAL
bal number;
begin
acno:= x1;
acname:=x2;
add:=x3;
bal:=x4;
insert into bankmaster values(acno,acname,add,bal);
dbms_output.put_line('Record Inserted');
end;
SQL> @ b1;
14 /
Procedure created.
SQL> exec custadd(8080,'Anish','Trichy',5000);
Record Inserted
PL/SQL procedure successfully completed.
SQL> exec custadd(8081,'Sham','Salem',10000);
Record Inserted
PL/SQL procedure successfully completed.
SQL> exec custadd(8082,'Yugesh','Erode',7000);
Record Inserted
PL/SQL procedure successfully completed.
SQL> select * from bankmaster;
ACCNO ACCNAME ADDRESS BALANCE
--------- -------------------- -------------------- ---------
8080 Anish Trichy 5000
8081 Sham Salem 10000
8082 Yugesh Erode 7000
SQL> ed b2;
create or replace procedure custdelete( x number) as
acno number(10);
beginacno:=x;
8/2/2019 DBMS Lab Manual - 1
36/53
M.A.M. SCHOOL OF ENGINEERING, SIRUGANUR, TIRUCHIRAPPALLI 621105
DEPARTMENT OF C.S.E.
CS1256 - DBMS LAB MANUAL
delete from bankmaster where accno = acno;
delete from bankmaster where accno = acno;
dbms_output.put_line('Record Deleted');end;
SQL> @ b2;
9 /
Procedure created.
SQL> exec custdelete(8080);
Record DeletedSQL> select * from bankmaster;
ACCNO ACCNAME ADDRESS BALANCE
--------- -------------------- -------------------- ---------
8081 Sham Salem 10000
8082 Yugesh Erode 7000
SQL> ed b3;
create or replace procedure custtrans( x1 number,
x2 varchar2, x3 number) as
acno number(15);
actype varchar2(20);
bal number(10);
taccno number(15);
taccname varchar2(20);
tbalance number(10);tdate date;
begin
acno:=x1;
actype:=x2;
bal:=x3;
select accno,accname,balance into
taccno,taccname,tbalance from bankmaster where
accno = acno ;
if SQL%FOUND then
dbms_output.put_line('Record Found');
tdate:=sysdate;
if actype = 'D' then
insert into trans
values(taccno,taccname,tdate,actype,bal);
update bankmaster set balance = tbalance + bal where
accno=acno;
else
insert into trans
values(taccno,taccname,tdate,actype,bal);
update bankmaster set balance = tbalance - bal where
accno=acno;
end if;
else
8/2/2019 DBMS Lab Manual - 1
37/53
M.A.M. SCHOOL OF ENGINEERING, SIRUGANUR, TIRUCHIRAPPALLI 621105
DEPARTMENT OF C.S.E.
CS1256 - DBMS LAB MANUAL
dbms_output.put_line('No Record Not Found');
end if;
end;
SQL> @ b3;
28 /Procedure created.
SQL> exec custtrans(8081,'D',2000);
Record Found
PL/SQL procedure successfully completed.
SQL> select * from trans;
ACCNO ACCNAME TRANSDATE T AMT
--------- -------------------- --------- - ---------
8081 Sham 09-OCT-06 D 2000
SQL> exec custtrans(8082,'W',2000);
Record Found
PL/SQL procedure successfully completed.
SQL> select * from trans;
ACCNO ACCNAME TRANSDATE T AMT
--------- -------------------- --------- - ---------
8081 Sham 09-OCT-06 D 2000
8082 Yugesh 09-OCT-06 W 2000
SQL> select * from bankmaster;
ACCNO ACCNAME ADDRESS BALANCE
--------- -------------------- -------------------- ---------
8081 Sham Salem 12000
8082 Yugesh Erode 5000
Result:
Thus the procedure for bank process was written
and executed.
Ex No.11 PAYROLL PROCESSING
8/2/2019 DBMS Lab Manual - 1
38/53
M.A.M. SCHOOL OF ENGINEERING, SIRUGANUR, TIRUCHIRAPPALLI 621105
DEPARTMENT OF C.S.E.
CS1256 - DBMS LAB MANUAL
AIM:
To develop a package for Payroll processing.
Procedure:
1.Create the table for StaffMaster2.Insert the values in the StaffMaster table.3.Write the procedure to insert the values in the
payment table after calculating the net salary and
gross salary.
SQL> Create Table StaffMaster( ID Number(3) , Name
Varchar2(10) , Category Varchar2(1), BasicSalary
Number(8,2) , HRA Number(2), DA Number(2), EPF Number(5),LIC Number(5) );
Table created.
SQL> Desc StaffMaster;
Name Null? Type
--------------------- -------- ----------------
ID NUMBER(3)
NAME VARCHAR2(10)
CATEGORY VARCHAR2(1)
BASICSALARY NUMBER(8,2)
HRA NUMBER(2)DA NUMBER(2)
EPF NUMBER(5)
LIC NUMBER(5)
SQL> Insert Into StaffMaster Values( 101, 'Siva','T',
8000, 10, 15, 1000 , 500 );
1 row created.
SQL> Insert Into StaffMaster Values( 102,
'Kumar','N',10000, 10, 15, 800 , 600 );
1 row created.
SQL> Select * from StaffMaster;
ID NAME C BASICSALARY HRA DA
EPF LIC
---------- ---------- - ----------- ---------- ----------
----------
101 Siva T 8000 10 15 1000
500
102 Kumar N 10000 10 15 800
600
8/2/2019 DBMS Lab Manual - 1
39/53
M.A.M. SCHOOL OF ENGINEERING, SIRUGANUR, TIRUCHIRAPPALLI 621105
DEPARTMENT OF C.S.E.
CS1256 - DBMS LAB MANUAL
SQL> Create Table PayMent( ID Number(3), Name
Varchar2(10),
2 GrossSalary Number(10,2), NetSalary Number(10,2) );Table created.
SQL> Desc PayMent;
Name Null? Type
----------------------------------------- -------- ------
----------
ID
NUMBER(3)
NAME
VARCHAR2(10)
GROSSSALARYNUMBER(10,2)
NETSALARY
NUMBER(10,2)
SQL> Select * from PayMent;
no rows selected
SQL> Create or Replace Procedure PayRoll( X Number) As
PName Varchar2(10);PID Number(3);
PHRA Number(2) := 0;
PDA Number(2) := 0;
PEPF Number(5) := 0;
PLIC Number(5) := 0;
PBasicSalary Number(8,2) :=0;
PGrossSal Number(10,2) := 0;
PNetSal Number(10,2) := 0;
Begin
PID := X;
Select Name, BasicSalary, HRA, DA, EPF, LICInto PName, PBasicSalary, PHRA, PDA, PEPF, PLIC
from StaffMaster Where ID = PID;
PGrossSal := PBasicSalary + (PBasicSalary * (PHRA /
100) ) +
(PBasicSalary *(PDA / 100) );
PNetSal := PGrossSal - ( PEPF + PLIC );
Insert Into payment Values( PID, PName, PGrossSal,
PNetSal );
End;
/
Procedure created.
8/2/2019 DBMS Lab Manual - 1
40/53
M.A.M. SCHOOL OF ENGINEERING, SIRUGANUR, TIRUCHIRAPPALLI 621105
DEPARTMENT OF C.S.E.
CS1256 - DBMS LAB MANUAL
SQL> Select * from PayMent;
no rows selected
SQL> EXEC PayRoll(101);
PL/SQL procedure successfully completed.
SQL> EXEC PayRoll(102);
PL/SQL procedure successfully completed.
SQL> Select * from PayMent;
ID NAME GROSSSALARY NETSALARY
---------- ---------- ----------- ----------
101 Siva 10000 8500
102 Kumar 12500 11100
Result:
Thus the procedure for bank process was
written and executed.
IMPLEMENTATION OF NORMALIZATION
Ex No:12
AIM:Create a table called customer_order and implement the concept of
Normalization.
PROCEDURES:
1NF Eliminates repeating groups-make a separate table for each set of related
attributes, and give each table a primary key.2NF Eliminates redundant data-if an attribute depends on only part of a multi valued
key, remove it to separate table.
3NF Eliminates columns not dependent on key-if an attribute do not contribute to a
description of the key, remove them to a separate table.
8/2/2019 DBMS Lab Manual - 1
41/53
M.A.M. SCHOOL OF ENGINEERING, SIRUGANUR, TIRUCHIRAPPALLI 621105
DEPARTMENT OF C.S.E.
CS1256 - DBMS LAB MANUAL
BCNF Boyce Codd Normal form If there are non-trivial dependencies between
candidate key attributes, separate them out into distinct tables.
4NF Isolate Independent Multiple Relationships No table may contain two or
more 1:n or n:m relationships that are not directly related.
5NF Isolate Semantically Related Multiple Relationships There may be practical
constrains on information that justify separating logically related many-to- many
relationships.
ONF Optimal Normal Form- a model limited to only simple (elemental) Facts, as
expressed in Object Role Model notation.
DKNF Domain-key Normal Form a model free from all modificationanomalies.
ALGORITHM:
Table description: customer_order
Column_name Data_type Constraint
Cust_name Char(25) Not null
Cust_order_date Date Not null
Cust_id Number(6) Not null
Order_item Varchar(35) -
SQL> CREATE TABLE CUSTOMER_ORDER (CUST_NAME CHAR(25)NOT NULL, CUST_ORDER_DATE DATE NOT NULL, CUST_IDNUMBER(6) NOT NULL, CUST_ORDER_ITEM VARCHAR2(35));
TABLE CREATED.
SQL> INSERT INTO CUSTOMER_ORDER VALUES( K.SANJAY, 16-
FEB-06, 17, CLOTHS,PAPER,UTENSILS);
SQL> SELECT * FROM CUSTOMER_ORDER;
CUST_NAME CUST_ORDE CUST_ID CUST_ORDER_ITEM------------------ ------------------ ------------ ---------------------------------
K.SANJAY 16-FEB-06 17 CLOTHS,PAPER,UTENSILS
8/2/2019 DBMS Lab Manual - 1
42/53
M.A.M. SCHOOL OF ENGINEERING, SIRUGANUR, TIRUCHIRAPPALLI 621105
DEPARTMENT OF C.S.E.
CS1256 - DBMS LAB MANUAL
SQL> CREATE TABLE CUSTOMER ( CUST_NAME VARCHAR2(15) NOT
NULL, CUST_ID NUMBER(6) NOT NULL, PRIMARY KEY(CUST_ID));TABLE CREATED.
SQL> CREATE TABLE ITEM_ORDER (CUST_ID NUMBER(6) NOT NULL,
ORDER_ID NUMBER(6) NOT NULL, ORDER_DATE DATE,
ORDER_ITEM VARCHAR2(20), PRIMARY KEY(CUST_ID, ORDER_ID),
FOREIGN KEY(CUST_ID) REFERENCES CUSTOMER);
TABLE CREATED.
SQL>INSERT INTO CUSTOMER VALUES ( K.SANJAY, 17);
SQL> INSERT INTO ITEM_ORDER VALUES(17, 1001, SYSDATE,
CLOTHS);
SQL> INSERT INTO ITEM_ORDER VALUES(17, 1002, SYSDATE,
PAPER);
SQL> INSERT INTO ITEM_ORDER VALUES(17, 1003, SYSDATE,
UTENSILS);
SQL> SELECT * FROM CUSTOMER;CUST_NAME CUST_ID
--------------- ----------
K.SANJAY 17
SQL> SELECT * FROM ITEM_ORDER ;
CUST_ID ORDER_ID ORDER_DAT ORDER_ITEM
---------- ---------- --------- ---------------
17 1001 24-FEB-06 CLOTHES
17 1004 22-FEB-06 PAPERS17 1002 24-FEB-06 UTENSILS
RESULT:Thus the table was created and normalization was implemented on
that table.
Ex No: 13
AIM:
8/2/2019 DBMS Lab Manual - 1
43/53
M.A.M. SCHOOL OF ENGINEERING, SIRUGANUR, TIRUCHIRAPPALLI 621105
DEPARTMENT OF C.S.E.
CS1256 - DBMS LAB MANUAL
To study and execute the all SQL commands.
ALGORITHM:SQL> create table x05mcs_categoryheader(cat_code number(5), cat_desc
varchar2(20));
Table created.
SQL> desc x05mcs_categoryheader;
Name Null? Type
-------------------------------------- -------- ----------------------------
CAT_CODE NUMBER(5)
CAT_DESC VARCHAR2(20)
SQL> create table x05mcs_routeheader ( route_id number(5), route_no
number(5), cat_code number(5), origin varchar2(20), destination varchar2(20),
fare number(7,2), distance number(3), capacity number(3));
Table created.
SQL> create table x05mcs_placeheader ( place_id number(5), place_name
varchar2(20), place_address varchar2(20), bus_station varchar2(20));
Table created.
SQL> create table x05mcs_fleetheader ( fleet_id number(5), day date, route_id
number(5), cat_code number (5));
Table created.
SQL> create table x05mcs_ticketheader (fleet_id number(5), ticket_no
number(5), doi date, dot date, time_travel char(8), board_place varchar2(20),origin varchar2(20), destination varchar2(20), adults number(3), children
number(3), total_fare number(7,2), route_id number(3));
Table created.
SQL> create table x05mcs_ticketdetail ( ticket_no number(5), name
varchar2(20), sex char(1), age number(5), fare number(5,2));
Table created.
8/2/2019 DBMS Lab Manual - 1
44/53
M.A.M. SCHOOL OF ENGINEERING, SIRUGANUR, TIRUCHIRAPPALLI 621105
DEPARTMENT OF C.S.E.
CS1256 - DBMS LAB MANUAL
SQL> create table x05mcs_item ( ord_id number(4), item_id number(4),
actual_price number(5), qty number(5), prod_id number(4));
Table created.
SQL> select * from tab;
TNAME TABTYPE CLUSTERID
---------------------------------------------------------------------------
X05MCS_CATEGORYHEADER TABLE
X05MCS_FLEETHEADER TABLE
X05MCS_ITEM TABLE
X05MCS_PLACEHEADER TABLEX05MCS_ROUTEHEADER TABLE
X05MCS_TICKETDETAIL TABLE
X05MCS_TICKETHEADER TABLE
8 rows selected.
SQL> desc x05mcs_routeheader;
Name Null? Type
---------------------------------- -------- ----------------------------
ROUTE_ID NUMBER(5)ROUTE_NO NUMBER(5)
CAT_CODE NUMBER(5)
ORIGIN VARCHAR2(20)
DESTINATION VARCHAR2(20)
FARE NUMBER(7,2)
DISTANCE NUMBER(3)
CAPACITY NUMBER(3)
SQL> desc x05mcs_placeheader;
Name Null? Type
----------------------------------- -------- ----------------------------
PLACE_ID NUMBER(5)
PLACE_NAME VARCHAR2(20)
PLACE_ADDRESS VARCHAR2(20)
BUS_STATION VARCHAR2(20)
SQL> desc x05mcs_fleetheader;
Name Null? Type
----------------------------------- -------- ----------------------------FLEET_ID NUMBER(5)
8/2/2019 DBMS Lab Manual - 1
45/53
M.A.M. SCHOOL OF ENGINEERING, SIRUGANUR, TIRUCHIRAPPALLI 621105
DEPARTMENT OF C.S.E.
CS1256 - DBMS LAB MANUAL
DAY DATE
ROUTE_ID NUMBER(5)
CAT_CODE NUMBER(5)
SQL> desc x05mcs_ticketheader;
Name Null? Type
----------------------------------- -------- ----------------------------
FLEET_ID NUMBER(5)
TICKET_NO NUMBER(5)
DOI DATE
DOT DATE
TIME_TRAVEL CHAR(8)
BOARD_PLACE VARCHAR2(20)
ORIGIN VARCHAR2(20)
DESTINATION VARCHAR2(20)
ADULTS NUMBER(3)
CHILDREN NUMBER(3)
TOTAL_FARE NUMBER(7,2)
ROUTE_ID NUMBER(3)
SQL> desc x05mcs_ticketdetail;
Name Null? Type----------------------------------- -------- ----------------------------
TICKET_NO NUMBER(5)
NAME VARCHAR2(20)
SEX CHAR(1)
AGE NUMBER(5)
FARE NUMBER(5,2)
SQL> desc x05mcs_item;
Name Null? Type
-------------------------------------------- ----------------------------ORD_ID NUMBER(4)
ITEM_ID NUMBER(4)
ACTUAL_PRICE NUMBER(5)
QTY NUMBER(5)
PROD_ID NUMBER(4)
SQL> insert into x05mcs_categoryheader values(01,'superdeluxe');
1 row created.
SQL> insert into x05mcs_categoryheader values(02,'deluxe');1 row created.
8/2/2019 DBMS Lab Manual - 1
46/53
M.A.M. SCHOOL OF ENGINEERING, SIRUGANUR, TIRUCHIRAPPALLI 621105
DEPARTMENT OF C.S.E.
CS1256 - DBMS LAB MANUAL
SQL> insert into x05mcs_categoryheader values(03,'superfast');
1 row created.
SQL> insert into x05mcs_categoryheader values(04,'normal');
1 row created.
SQL> select * from x05mcs_categoryheader;
CAT_CODE CAT_DESC
----------------- --------------------
1 SUPERDELUXE
2 DELUXE3 SUPERFAST
4 NORMAL
SQL> insert into x05mcs_routeheader values (101, 33, 01, 'madurai', 'madras',35, 250, 50);
1 row created.
SQL> insert into x05mcs_routeheader values (102, 25, 02, 'trichy', 'madurai', 40,
159, 50);
1 row created.
SQL> insert into x05mcs_routeheader values (103, 15, 03, 'thanjavur', 'madurai',
59, 140, 50);
1 row created.
SQL> insert into x05mcs_routeheader values(104,36,04,'madras', 'bangalore',
79,375,50);
1 row created.
SQL> insert into x05mcs_routeheader values(105,40,01,'bangalore', 'madras',80,375,50);
1 row created.
SQL> select * from x05mcs_routeheader;
Route_Id Route_No Cat_Code Origin Destination Fare Distance Capacity
---------------------------------------------------------------------------------------------------------
101 33 1 Madurai Madras 35 250 50
102 25 2 Trichy Madurai 40 159 50
103 15 3 Thanjavur Madurai 59 140 50
104 36 4 Madras Bangalore 79 375 50105 40 1 Bangalore Madras 80 375 50
8/2/2019 DBMS Lab Manual - 1
47/53
M.A.M. SCHOOL OF ENGINEERING, SIRUGANUR, TIRUCHIRAPPALLI 621105
DEPARTMENT OF C.S.E.
CS1256 - DBMS LAB MANUAL
SQL> insert into x05mcs_placeheader values(01 ,'madras','10,ptc road','parrys');
1 row created.
SQL> insert into x05mcs_placeheader values(02 , 'madurai', '21,canalbank', 'kknagar');
1 row created.
SQL> insert into x05mcs_placeheader values(03 ,'trichy', '11,firstcrossroad',
'bheltown');
1 row created.
SQL> insert into x05mcs_placeheader values(04 ,'bangalore','15 firstmainroad','cubbon park');
1 row created.
SQL> insert into x05mcs_placeheader values(05 ,'hyderabad',
'115,lakeviewroad', 'charminar');
1 row created.
SQL> insert into x05mcs_placeheader values(06 , 'thanjavour',
'12,templeroad','junction');
1 row created.
SQL> select * from x05mcs_placeheader;PLACE_ID PLACE_NAME PLACE_ADDRESS BUS_STATION
-------------------------------------------------------------------------------------------
1 Madras 10,PTC Road Parrys
2 Madurai 21,CanalBank KK Nagar
3 Trichy 11,FirstCrossRoad BhelTown
4 Bangalore 15 FirstMainRoad Cubbon Park
5 Hyderabad 115,LakeViewRoad Charminar
6 Thanjavour 12,TempleRoad Junction
6 rows selected.
SQL> insert into x05mcs_fleetheader values(01,'10-apr-96',101,01);
1 row created.
SQL> insert into x05mcs_fleetheader values(02,'10-apr-96',101,01);
1 row created.
SQL> insert into x05mcs_fleetheader values(03,'10-apr-96',101,01);
1 row created.
SQL> insert into x05mcs_fleetheader values(04,'10-apr-96',102,02);
8/2/2019 DBMS Lab Manual - 1
48/53
M.A.M. SCHOOL OF ENGINEERING, SIRUGANUR, TIRUCHIRAPPALLI 621105
DEPARTMENT OF C.S.E.
CS1256 - DBMS LAB MANUAL
1 row created.
SQL> insert into x05mcs_fleetheader values(05,'10-apr-96',102,03);1 row created.
SQL>insert into x05mcs_fleetheader values(06,'10-apr-96',103,04);1 row created.
SQL> SELECT * FROM X05MCS_FLEETHEADER;
FLEET_ID DAY ROUTE_ID CAT_CODE
-----------------------------------------------------------------------
1 10-APR-96 101 12 10-APR-96 101 1
3 10-APR-96 101 1
4 10-APR-96 102 2
5 10-APR-96 102 3
6 10-APR-96 103 4
6 rows selected.
SQL> insert into x05mcs_ticketheader values(01 ,01 ,'10-apr-96','10-may-
96','15:00:00','parrys);1 row created.
SQL> insert into x05mcs_ticketheader values(02 ,02 ,'12-apr-96','05-may-
96','09:00:00','kk nagar);
1 row created.
SQL> insert into x05mcs_ticketheader values(03 ,03 ,'21-apr-96','15-may-
96','21:00:00','cubbon);
1 row created.
SQL> insert into x05mcs_ticketheader values(04 ,04 ,'25-apr-96','25-may-
96','10:00:00','charm);1 row created.
SQL> insert into x05mcs_ticketheader values(05 ,250 ,'30-apr-96','22-may-
96','15:00:00','parryas);
1 row created.
SQL> select * from x05mcs_ticketheader;
Fleet_id Ticket_no DOI DOT time_tra board_place
---------------------------------------------------------------------------------------------------
8/2/2019 DBMS Lab Manual - 1
49/53
M.A.M. SCHOOL OF ENGINEERING, SIRUGANUR, TIRUCHIRAPPALLI 621105
DEPARTMENT OF C.S.E.
CS1256 - DBMS LAB MANUAL
1 1 10-APR-96 10-MAY-96 15:00:00 Parrys
2 2 12-APR-96 05-MAY-96 09:00:00 KK Nagar
3 3 21-APR-96 15-MAY-96 21:00:00 Cubbon Park4 4 25-APR-96 25-MAY-96 10:00:00 Charminar
5 2 30-APR-96 22-MAY-96 15:00:00 Parrys
Origin Destination Adults Children Total_fare Route_id
----------------------------------------------------------------------------------------------------
Madras Madurai 1 1 60 101
Madurai Madras 2 1 60 102
Bangalore Madras 4 2 400 101
Hyderabad Madras 10 0 500 103
Madras Cochin 2 2 141 103
SQL>insert into x05mcs_ticketdetail values(01,'charu','f',24,14.00);
1 row created.
SQL>insert into x05mcs_ticketdetail values(01,'latha','f',10,15.55);
1 row created.
SQL> insert into x05mcs_ticketdetail values(02,'anand','m',28,17.80);
1 row created.
SQL> insert into x05mcs_ticketdetail values(02,'gautham','m',24,16.00);1 row created.
SQL>insert into x05mcs_ticketdetail values(02,'x05mcs','m',09,17.65);
1 row created.
SQL>insert into x05mcs_ticketdetail values(05,'sandeep','m',30,18.00);
1 row created.
SQL> select * from x05mcs_ticketdetail;
TICKET_NO NAME S AGE FARE---------------------------------------------------------------------
1 Charu F 24 14
1 Latha F 10 15.55
2 Anand M 28 17.8
2 Gautham M 24 16
2 Bala M 9 17.65
5 Sandeep M 30 18
6 rows selected.
SQL> insert into x05mcs_item values(2000,105,5000,500,111 );1 row created.
8/2/2019 DBMS Lab Manual - 1
50/53
M.A.M. SCHOOL OF ENGINEERING, SIRUGANUR, TIRUCHIRAPPALLI 621105
DEPARTMENT OF C.S.E.
CS1256 - DBMS LAB MANUAL
SQL> insert into x05mcs_item values(2001,3000,4050,600,112 );
1 row created.
SQL> select * from x05mcs_item;
ORD_ID ITEM_ID ACTUAL_PRICE QTY PROD_ID
---------------------------------------------------------------------------------
2000 105 5000 500 111
2001 3000 4050 600 112
SQL> alter table x05mcs_routeheader add comments long;
Table altered.
SQL> desc x05mcs_routeheader;
Name Null? Type
----------------------------------------- -------- ----------------------------
ROUTE_ID NUMBER(5)
ROUTE_NO NUMBER(5)
CAT_CODE NUMBER(5)
ORIGIN VARCHAR2(20)
DESTINATION VARCHAR2(20)
FARE NUMBER(7,2)
DISTANCE NUMBER(3)CAPACITY NUMBER(3)
COMMENTS LONG
SQL> alter table x05mcs_routeheader drop column comments;
Table altered.
SQL> desc x05mcs_routeheader;Name Null? Type
----------------------------------------- -------- ----------------------------
ROUTE_ID NUMBER(5)
ROUTE_NO NUMBER(5)CAT_CODE NUMBER(5)
ORIGIN VARCHAR2(20)
DESTINATION VARCHAR2(20)
FARE NUMBER(7,2)
DISTANCE NUMBER(3)
CAPACITY NUMBER(3)
SQL> select distinct cat_code from x05mcs_routeheader order by
cat_code desc;
CAT_CODE
----------
4
3
8/2/2019 DBMS Lab Manual - 1
51/53
M.A.M. SCHOOL OF ENGINEERING, SIRUGANUR, TIRUCHIRAPPALLI 621105
DEPARTMENT OF C.S.E.
CS1256 - DBMS LAB MANUAL
2
1
SQL> desc x05mcs_routeheader;
Name Null? Type
----------------------------------------- -------- ---------------
ROUTE_ID NUMBER(5)
ROUTE_NO NUMBER(5)
CAT_CODE NUMBER(5)
ORIGIN VARCHAR2(20)
DESTINATION VARCHAR2(20)
FARE NUMBER(7,2)
DISTANCE NUMBER(3)
CAPACITY NUMBER(3)
SQL> alter table x05mcs_routeheader modify distance number(4);
Table altered.
SQL> desc x05mcs_routeheader;Name Null? Type
----------------------------------------- -------- ---------------
ROUTE_ID NUMBER(5)
ROUTE_NO NUMBER(5)CAT_CODE NUMBER(5)
ORIGIN VARCHAR2(20)
DESTINATION VARCHAR2(20)
FARE NUMBER(7,2)
DISTANCE NUMBER(4)
CAPACITY NUMBER(3)
SQL> grant alter,update,insert on x05mcs_routeheader to x05mcs07;
Grant succeeded.
SQL> revoke alter,update,insert on x05mcs_routeheader from x05mcs07;Revoke succeeded.
SQL> create table x05mcs_routedetail (route_id number(5), place_id number(5),
nonstop char(1));Table created.
SQL> desc x05mcs_routedetail;
Name Null? Type
----------------------------------------- -------- ----------------------------
ROUTE_ID NUMBER(5)
8/2/2019 DBMS Lab Manual - 1
52/53
M.A.M. SCHOOL OF ENGINEERING, SIRUGANUR, TIRUCHIRAPPALLI 621105
DEPARTMENT OF C.S.E.
CS1256 - DBMS LAB MANUAL
PLACE_ID NUMBER(5)
NONSTOP CHAR(1)
SQL>insert into x05mcs_routedetail values(105,01,'n')
1 row created.
SQL>insert into x05mcs_routedetail values(102,02,'s')
1 row created.
SQL>insert into x05mcs_routedetail values(106,01,'s')
1 row created.
SQL>insert into x05mcs_routedetail values(108,05,'n')1 row created.
SQL> select * from x05mcs_categoryheader;
CAT_CODE CAT_DESC
---------- --------------------
1 SUPERDELUXE
2 DELUXE
3 SUPERFAST
4 NORMAL
SQL> savepoint sp1;
Savepoint created.
SQL> insert into x05mcs_categoryheader values(5,'highspeed');
1 row created.
SQL> savepoint sp2;
Savepoint created.
SQL> delete from x05mcs_categoryheader where cat_code=4;1 row deleted.
SQL> savepoint sp3;
Savepoint created.
SQL> insert into x05mcs_categoryheader values(16 ,'ultimatespeed');
1 row created.
SQL> select * from x05mcs_categoryheader;CAT_CODE CAT_DESC
---------- --------------------
1 SUPERDELUXE
8/2/2019 DBMS Lab Manual - 1
53/53
M.A.M. SCHOOL OF ENGINEERING, SIRUGANUR, TIRUCHIRAPPALLI 621105
DEPARTMENT OF C.S.E.
CS1256 - DBMS LAB MANUAL
2 DELUXE
3 SUPERFAST
5 HIGHSPEED16 ULTIMATESPEED
SQL> rollback to sp2;
Rollback complete.
SQL> select * from x05mcs_categoryheader;
CAT_CODE CAT_DESC
---------- --------------------
1 SUPERDELUXE
2 DELUXE
3 SUPERFAST
4 NORMAL
5 HIGHSPEED
SQL> rollback to sp1;
Rollback complete.
SQL> select * from x05mcs_categoryheader;
CAT_CODE CAT_DESC---------- --------------------
1 SUPERDELUXE
2 DELUXE
3 SUPERFAST
4 NORMAL
SQL> commit;
Commit complete.
RESULT:Thus the SQL commands are executed and results were verified.