DBS-BIT&BSE-Lab 11 PL-SQL-3

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Faculty of Computing & Information Technology

CC-215-L: Database Systems Lab


BS(IT&SE) Morning - Fall 2021, Semester Spring 2023
LAB – 10
Course & Lab Instructor: Dr. Asif Sohail
Objectives:
1. PL/SQL Revision
2. Procedures & Functions
3. Triggers

Allowed time: 120 mins.

Instructions:
1. Gossips are not allowed.
2. Teacher assistants are for your help, so be nice with them. Respect them as they are teaching you.
Raise your hands if you have some problem and need help from TA. Avoid calling them by raising
your voice and disturbing the environment of Lab.
3. TA may deduct your marks for any kind of ill-discipline or misconduct from your side.
4. Evaluation will be considered final and you cannot debate for the marks. So, focus on performing
the tasks when the time is given to you.
5. Paste the query as well as result table screenshot as a result of each task
Sample:
Display All the Employees from emp table
Solution:
Select * from emp

EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO

7369 SMITH CLERK 7902 12/17/1980 800 - 20

7499 ALLEN SALESMAN 7698 02/20/1981 1600 300 30

7521 WARD SALESMAN 7698 02/22/1981 1250 500 30

7566 JONES MANAGER 7839 04/02/1981 2975 - 20

7654 MARTIN SALESMAN 7698 09/28/1981 1250 1400 30


Task 01: [45 Marks]

1. Create a table emp_accounts using emp table. The table has the attributes empno,
ename, job, hiredate, sal, comm at the time of table creation. Afterwards, add the
following attributs in the table: (2)

2. Create a table LOAN with the following attributes: (2)

3. Create a table LOAN_RETURN with the following attributes: (2)

4. Create a PL/SQL function raise_sal that raises the sal of all the employees of
emp_accounts table by 10% of their exisiting sal. (3)

5. Create a database trigger sal_update that fires before the update of each row of
amp_accounts table. The trigger should display the existing sal and the updated sal
of the employee(s). (3)

6. Replace the above trigger sal_update that fires before the update of each row of
amp_accounts table. The trigger should ensure that the raise in sal should not
exceed 50% of the existing sal of the employees. In that case, the trigger should
deny the update by raising an application error.
(3)

7. Create a database trigger compute_grade that fires before the insertion of each
row of amp_accounts table. The trigger compute the grade of the newly inserted
employee on the basis of sal using the following rules:
(5)

8. Create a database trigger post_insert_loan that fires after the insertion of each
row of loan table. The trigger should set the arrears column of emp_accounts with
the loan_amount inserted. Verify the working of the trigger by inserting a row in
LOAN table.
(5)

9. Create a database trigger post_insert_loan_return that fires after the insertion of


each row of loan_return table. The trigger should update the arrears column of
emp_accounts with the ret_amount. A loan can be returned in multiple
installments, and with each return, the arrears column should be updated
accordingly. The status column of loan table should be set to "returned", once all
the loan amount has been returned.
(10)

10. Create a database trigger pre_insert_loan that fires before the insertion of each
row of loan table. The trigger will allow the insertion of a row only for the employees
with zero arrears. Furthermore, the trigger will also ensure that the loan amount can
be up to the sal of the employee. In case of failure, the trigger should raise an
application error with an error message "Loan amount is above salary" and
"Ineligible for loan due to arrears" respectively.
(10)

You might also like