0% found this document useful (0 votes)
13 views31 pages

MCABC2P Lab Spiral - FINAL

The document serves as a record book for the Relational Database Management Systems lab for Master of Computer Application students, detailing various SQL and PL/SQL queries and their aims. It includes practical exercises such as displaying employee details, calculating percentages, updating salaries, and creating database triggers and packages. The document also certifies the completion of practical records for students in their second semester of the first year.

Uploaded by

Prasanth C
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)
13 views31 pages

MCABC2P Lab Spiral - FINAL

The document serves as a record book for the Relational Database Management Systems lab for Master of Computer Application students, detailing various SQL and PL/SQL queries and their aims. It includes practical exercises such as displaying employee details, calculating percentages, updating salaries, and creating database triggers and packages. The document also certifies the completion of practical records for students in their second semester of the first year.

Uploaded by

Prasanth C
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/ 31

DIRECTORATE OF DISTANCE EDUCATION

(University with Potential for Excellence)

Master of Computer Application


Ist YEAR – IInd Semester

RELATIONAL DATABASE
MANAGEMENT SYSTEMS
LAB
(MCABC2P)
RECORD BOOK
DIRECTORATE OF DISTANCE EDUCATION

(University with Potential for Excellence)

Bonafide Certificate

This is to certify that bonafide that record of Relational Database Management


Systems – MCABC2P practical record done by
Mr/Mrs/Ms Register Number
for that Master of Computer Application I st year IInd Semester.

Subject & Code : RDBMS LAB – MCABC2P

Date of Examination: _______________

Internal Examiner External Examiner


CONTENT

S.No. SECTION - I (SQL Query) Page No


1 Display all the details of all employees working in the company
Display ssn,lname,fname,address of employees who work in
2 particular Department

3 Retrieve the name and salary of every employee


4 Retrieve all distinct salary values
5 Retrieve all employee names whose address is in ”Bellaire‟
6 Retrieve all employees who were born during the 1950s

7 Retrieve all employees in department 5whose salary is between


50,000 and 60,000(inclusive)
8 Retrieve the names of all employees who do not have supervisors
9 Retrieve SSN and department name for all employees
SECTION - II (PL/SQL Query)
Write a PL/SQL code to calculate and percentage of marks of the
10 students in four subjects.
Write a PL/SQL code to calculate the total salary of first n records
11 of employee table. The values of n is passed to cursor as parameter.
Write a PL/SQL code to update the salary of employees who earn
12 less than the average salary.
Write a row trigger to insert the existing values of the salary table in
13 to a new table when the salary table is updated.
Write a PL/SQL code to create
a) Package specification
14 b) Package body
For the insert, retrieve, update and delete operations on a student
table.

15 To perform Banking operation using procedures.


SECTION - I (SQL Query)

1. Display all the details of all employees working in the company.

Aim :

To Display all the details of all employees working in the company.

Table Name :- Employee

Query :

SQL> select * from employee;

Output:

Result:

The above query was executed successfully for the details of all
employee.
1
2. Display ssn,lname,fname,address of employee who work in
Departmentno 7.

Aim:

To Display ssn,lname,fname,address of employee who work in


Department no 7.

Table Name :- Employee

Query:

SQL>select ssn,lname,fname,address from employee where dno=7;

Output:

Result:

The above query executed successfully for the details ssn,lname,fname,


address of employees who work in department no 7.

2
3. Retrieve the name and salary of every employee

Aim:

To retrieve the name and salary of every employee.

Table Name :- Employee

Query:

SQL> select fname,mname,lname,salary from employee;

Ouput:

Result:

The above query executed successfully for the name and salary of every
employee.
3
4. Retrieve all distinct salary employee.

Aim:

To Retrieve all distinct salary employee.

Table Name :- Employee

Query:

SQL>select distinct salary from employee;

Output:

Result:

The above query executed successfully for all the distinct salary values.
4
5. Retrieve all employee names whose address is in ‘Bellaire’.

Aim:

To Retrieve all employee names whose address is in ‘Bellaire’.

Table Name :- Employee

Query:

SQL>select fname,mname,lname from employee where


address="Bellaire";

Output:

Result:

The above query executed successfully for all employee names whose
address is in ‘Bellaire’.
5
6. Retrieve all employees who were born during the 1950s.

Aim:

To Retrieve all employees who were born during the 1950s.

Table Name:- Employee

Query:

SQL>select fname from employee where bdate between 01-01-50


and 31-12- 59;

Output:

Result:

The above query executed successfully for all employees who were born
during the 1950s.
6
7. Retrieve all employees in department 5 whose salary is
between 50,000 and 60,000(inclusive).

Aim:

To retrieve all employees in department 5 whose salary is between 50,000


and 60,000.

Table Name:- Employee

Query:

SQL>select * from employee where dno=5 and salary>=50000 and


salary <=60000;

Output:

Result:

The above query executed successfully for all employees in department 5


whose salary is between 50,000 and 60,000.

7
8. Retrieve the names of all employees who do not have supervisors.

Aim:

To retrieve the names of all employees who do not have supervisors.

Table Name:- Employee

Query:

SQL>select fname,mname,lname from employee where super ssn is


null;

Output:

Result:

The above query executed successfully for the names of all employees
who do not have supervisors.
8
9. Retrieve SSN and department name for all employees.

Aim:

To retrieve SSN and department name for all employees.

Table Name:- Employee

Query:

SQL>select ssn,department from employee;

Output:

Result:

The above query executed successfully for the SSN and department name
for all employees.
9
SECTION - II (PL/SQL Query)

1. Write a PL/SQL code to calculate and percentage of marks of the


students in four subjects.

Aim:

To Write a PL/SQL code to calculate and percentage of marks of the students in


four subjects.

Query:

PL/SQL>

DECLARE
roll_number number(10);
marks_subject1 number(10);
marks_subject2 number(10);
marks_subject3 number(10);
marks_subject4 number(10);
total_marks number(10);
percentage number(5,2);
BEGIN
roll_number :=&roll_number;
marks_subject1 :=&marks_subject1;
marks_subject2 :=&marks_subject2;
marks_subject3 :=&marks_subject3;
marks_subject4 :=&marks_subject4;

total_marks := marks_subject1 + marks_subject2 + marks_subject3 +


marks_subject4;
percentage :=(total_marks/400)*100;

dbms_output.put_line('roll number:' ||roll_number);


dbms_output.put_line('total marks:' || total_marks);
dbms_output.put_line('percentage:' || percentage ||'%');
END;
/

10
Output:

Result:

The above query executed successfully for the calculate and percentage of
marks of the students in four subjects.
11
2. Write a PL/SQL code to calculate the total salary of first n records
of employee table. The values of n is passed to cursor as parameter.
Aim:

To Write a PL/SQL code to calculate the total salary of first n records of


employee table. The values of n is passed to cursor as parameter.

Query 1:

PL/SQL>

CREATE TABLE employee_salary (


EMP_NO VARCHAR2(5) CONSTRAINT pk_emp_no PRIMARY KEY,
BASIC VARCHAR2(10) NOT NULL,
HRA VARCHAR2(10) NOT NULL,
DA VARCHAR2(10) NOT NULL,
TOTAL_DEDUCTION VARCHAR2(10) NOT NULL,
NET_SALARY VARCHAR2(10) NOT NULL,
GROSS_SALARY VARCHAR2(10) NOT NULL );

INSERT INTO EMPLOYEE_SALARY


VALUES(1,31000,8000,1000,5000,35000,40000);

INSERT INTO EMPLOYEE_SALARY


VALUES(2,15000,4000,1000,5000,15000,20000);

INSERT INTO EMPLOYEE_SALARY


VALUES(3,14000,4000,1000,5000,15000,19000);

INSERT INTO EMPLOYEE_SALARY


VALUES(4,14000,4000,1000,5000,15000,19000);

INSERT INTO EMPLOYEE_SALARY


VALUES(5,13000,4000,1000,5000,15000,18000);

12
Output:

Query: 2

PL/SQL>
DECLARE
Number_of_employee NUMBER;
Total_salary NUMBER := 0;
CURSOR ec(n NUMBER) IS
SELECT gross_salary
FROM employee_salary
WHERE TO_NUMBER(emp_no) <= n;
rw ec%ROWTYPE;
BEGIN
Number_of_employee := &Number_of_employee;
OPEN ec(Number_of_employee);

LOOP
FETCH ec INTO rw;
EXIT WHEN ec%NOTFOUND;

Total_salary := TO_NUMBER(rw.gross_salary) + Total_salary;


END LOOP;

CLOSE ec;

DBMS_OUTPUT.PUT_LINE('Total salary of ' || Number_of_employee || '


employee(s) is ' || Total_salary);

END;
/

13
Output:

Result:

The above query executed for the calculate the total salary of first n records of
employee table. The values of n is passed to cursor as parameter..

14
3. Write a PL/SQL code to update the salary of employees who earn
less than the average salary.

Aim:

To Write a PL/SQL code to update the salary of employees who earn less than
the average salary.

Query 1:

SELECT * FROM employee_salary;

Query: 2

PL/SQL>
DECLARE
average NUMBER;
bs NUMBER;
gs NUMBER;
diff NUMBER;
CURSOR ec IS
SELECT * FROM employee_salary;
rw ec%rowtype;
BEGIN
SELECT avg(basic) INTO average FROM employee_salary;
dbms_output.put_line('the average salary is'||average);

OPEN ec;
LOOP
FETCH ec INTO rw;
EXIT WHEN ec%notfound;

IF(rw.basic<=average)THEN
15
diff:=rw.basic-average;
UPDATE employee_salary
SET basic=average,gross_salary=gross_salary+diff
WHERE emp_no=rw.emp_no;

SELECT basic,gross_salary
INTO bs,gs
FROM employee_salary
WHERE emp_no=rw.emp_no;

dbms_output.put_line('the employee number is'||rw.emp_no);

dbms_output.put_line('old basic='||rw.basic||' old


gross_salary='||rw.gross_salary);

dbms_output.put_line('updated new basic='||bs||' new gross


salary is ='||gs);

END IF;
END LOOP;
END;
/
Output:

Result:

The above query executed for the update the salary of employees who earn less
than the average salary.

16
4. Write a row trigger to insert the existing values of the salary table in
to a new table when the salary table is updated.
Aim:

To Write a row trigger to insert the existing values of the salary table in to a
new table when the salary table is updated.

Query 1:

SELECT * FROM employee_salary;

Output:

Query: 2
CREATE TABLE backup (
emp_no VARCHAR2(5),
old_gross_salary VARCHAR2(10),
new_gross_salary VARCHAR2(10)
);

Output:

17
Query: 3

CREATE OR REPLACE TRIGGER t


AFTER UPDATE ON employee_salary
FOR EACH ROW
BEGIN
INSERT INTO backup (emp_no, old_gross_salary, new_gross_salary)
VALUES (:OLD.emp_no, :OLD.gross_salary, :NEW.gross_salary);
END;
/

Output:

Query: 4
UPDATE employee_salary SET gross_salary=44000
WHERE emp_no=1;

Output:

Query: 5

SELECT * FROM backup;

Output:

18
Query: 6

UPDATE employee_salary SET gross_salary=20000


WHERE emp_no=2;

Output:

Query: 7

SELECT * FROM backup;

Output:

Query: 8

UPDATE employee_salary SET gross_salary=48000


WHERE emp_no=1;

Output:

19
Query: 9

SELECT * FROM backup;

Ouput:

Result:

The above query executed for the row trigger to insert the existing values of the
salary table in to a new table when the salary table is updated.

20
5. Write a PL/SQL code to create.

a) Package specification
b) Package body

For the insert, retrieve, update and delete operations on a student table.
Aim:

To Write a PL/SQL code to create.

a) Package specification
b) Package body

For the insert, retrieve, update and delete operations on a student table.

Query: 1

CREATE TABLE student (


roll_no NUMBER PRIMARY KEY,
student_name VARCHAR2(100),
course VARCHAR2(100),
gender VARCHAR2(10)
);

Output:

Query: 2

CREATE OR REPLACE PACKAGE alloperation


IS
PROCEDURE insert_student(rno NUMBER, sname VARCHAR2, crc
VARCHAR2, gen VARCHAR2);
PROCEDURE retrieve_student(rno NUMBER);
PROCEDURE update_student(rno NUMBER, sname VARCHAR2);
PROCEDURE delete_student(rno NUMBER);
END alloperation;
/

Output:
21
Query: 3
CREATE OR REPLACE PACKAGE BODY alloperation
IS
PROCEDURE insert_student(rno NUMBER, sname VARCHAR2, crc
VARCHAR2, gen VARCHAR2)
IS
BEGIN
INSERT INTO student (roll_no, student_name, course, gender)
VALUES (rno, sname, crc, gen);
END insert_student;

PROCEDURE retrieve_student(rno NUMBER)


IS
sname student.student_name%TYPE;
crc student.course%TYPE;
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 retrieve_student;

PROCEDURE update_student(rno NUMBER, sname VARCHAR2)


IS
BEGIN
UPDATE student
SET student_name = sname
WHERE roll_no = rno;
END update_student;

PROCEDURE delete_student(rno NUMBER)


IS
BEGIN
DELETE FROM student
WHERE roll_no = rno;
END delete_student;
END alloperation;
/
22
Output:

Query: 4

BEGIN
alloperation.insert_student(111, 'Ravi', 'CS', 'Male');
alloperation.insert_student(112, 'Praveen', 'CS', 'Male');
alloperation.insert_student(113, 'Bhuvana', 'IT', 'Female');
alloperation.insert_student(114, 'Aparna', 'IT', 'Female');
END;
/

Output:

Query: 5

SELECT * FROM student;

Output:

Query: 6

BEGIN
alloperation.insert_student(444, 'Vivekananda', 'ECE', 'Male');
alloperation.retrieve_student(444);
alloperation.update_student(111, 'Swamy');
23
END;
/

Output:

Query: 7

SELECT * FROM student;

Output:

Query: 8

BEGIN
alloperation.delete_student(444);
END;
/

Output:

24
Query: 9

SELECT * FROM student;

Output:

Result:

The above query executed for the Package specification, Package body and for
For the insert, retrieve, update and delete operations on a student table..

25
6. To perform Banking operation using procedures.

Aim:

To perform Banking operation using procedures.

Query: 1

CREATE TABLE acct_master (


acct_no NUMBER(5) PRIMARY KEY,
acct_name VARCHAR2(10),
balance NUMBER(10)
);
Output:

Query: 2

INSERT INTO acct_master VALUES (1, 'aaa', 1000);


INSERT INTO acct_master VALUES (2, 'bbb', 100);
INSERT INTO acct_master VALUES (3, 'ccc', 1100);
INSERT INTO acct_master VALUES (4, 'ddd', 700);
INSERT INTO acct_master VALUES (5, 'eee', 1700);
Ouput:

26
Query: 3

SELECT * FROM acct_master;

Output:

Query: 4

DECLARE
xacct_no number(5);
xmin_bal number(5):=1000;
xbalance number(5);

BEGIN
xacct_no:=&xacct_no;

SELECT balance INTO Xbalance


FROM acct_master
WHERE acct_no=xacct_no;

IF(xbalance < xmin_bal)THEN

UPDATE acct_master
SET balance=balance-100
WHERE acct_no=xacct_no;

xbalance:=xbalance-100;
dbms_output.put_line('Rs 100 is deducted and current balance is ' ||
xbalance);

ELSE
dbms_output.put_line('Current balance is '||Xbalance);

27
END IF;

END;
/

Output:

Result:

The above query executed for the perform Banking operation using procedures.

28

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy