MCABC2P Lab Spiral - FINAL
MCABC2P Lab Spiral - FINAL
RELATIONAL DATABASE
MANAGEMENT SYSTEMS
LAB
(MCABC2P)
RECORD BOOK
DIRECTORATE OF DISTANCE EDUCATION
Bonafide Certificate
Aim :
Query :
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:
Query:
Output:
Result:
2
3. Retrieve the name and salary of every employee
Aim:
Query:
Ouput:
Result:
The above query executed successfully for the name and salary of every
employee.
3
4. Retrieve all distinct salary employee.
Aim:
Query:
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:
Query:
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:
Query:
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:
Query:
Output:
Result:
7
8. Retrieve the names of all employees who do not have supervisors.
Aim:
Query:
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:
Query:
Output:
Result:
The above query executed successfully for the SSN and department name
for all employees.
9
SECTION - II (PL/SQL Query)
Aim:
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;
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:
Query 1:
PL/SQL>
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;
CLOSE ec;
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:
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;
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:
Output:
Query: 2
CREATE TABLE backup (
emp_no VARCHAR2(5),
old_gross_salary VARCHAR2(10),
new_gross_salary VARCHAR2(10)
);
Output:
17
Query: 3
Output:
Query: 4
UPDATE employee_salary SET gross_salary=44000
WHERE emp_no=1;
Output:
Query: 5
Output:
18
Query: 6
Output:
Query: 7
Output:
Query: 8
Output:
19
Query: 9
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:
a) Package specification
b) Package body
For the insert, retrieve, update and delete operations on a student table.
Query: 1
Output:
Query: 2
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;
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
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
Output:
Query: 8
BEGIN
alloperation.delete_student(444);
END;
/
Output:
24
Query: 9
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:
Query: 1
Query: 2
26
Query: 3
Output:
Query: 4
DECLARE
xacct_no number(5);
xmin_bal number(5):=1000;
xbalance number(5);
BEGIN
xacct_no:=&xacct_no;
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