Professional Documents
Culture Documents
DBS-BIT&BSE-Lab 10 PL SQL
DBS-BIT&BSE-Lab 10 PL SQL
DBS-BIT&BSE-Lab 10 PL SQL
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
1. Create a PL/SQL block that computes the number of records of emp table using a
cursor. (3)
3. Create a PL/SQL function sal_status that receives salary of the employees and
returns either "above average salary" or "below average salary" on the basis of the
average salary of all the employees. (5)
6. Create a PL/SQL function bonus (empno) that computes the bonus amount
(=sal*years_of_service/100+x). The value of x is determined by the job of the
employee as per the following policy: (10)
Displays the sal comm empno ename and bonus of all emplyees in emp
7. Suppose that the maximum years of service of an employee is 30 years. The salary
of the employee is raised by x% of the current salary of the year. The number x is
passed as parameter to a PL/SQL procedure. The default value of the parameter x is
10. The procedure should display the empno, ename, hiredate, retirement date,
salary at the time of hiring, and the salary at the time of retirement of the
seniormost employee. (10)
8. Create a PL/SQL procedure aggregate that performs all the built-in aggregate
functions on sal column of employee table. The procedure should display count, sum,
average, max, and min without using any one of the built-in group functions. (10)
9. Create a PL/SQL function salary_encrypt that receives salary of the employees and
encrypts the sal of an employee as per the following rules: (10)
# is equivalent of thousands
@ is equivalent of hundreds
& is equivalent of tens
The digits 0,1,2,…,9 are replaced by a,b,c,…,j respectively.
Hint: translate('ab12cd34','abcd','wxyz;) = wx12yz34;
It is assumed that the sal can be up to 4 digits, and the sal is multiple of 10.
Examples:
Code for 4530: e#f@d&
Code for 8060: i#a@g&
10. Create a PL/SQL function salary_decrypt that receives the encrypted code of the
salary that is encrypted using the rules of the last task. The function should decrypt
the code. Verify the function using dual table. (10)
a. Include the sum of salaries (SAL) and commissions (COMM) for all employees
in the department.
b. Use the previously defined bonus function to compute the total bonus for that
department.
c. Assume that the total expense includes the total of salaries, commissions, and
bonuses for all employees in the specified department.
d. Return the calculated expense in function.
e. Displays the department wise expense of the company
12. Extend the above code to display highest expense dept and lowest one. (5)
Note: (You have to do this by expense fun you created.)
1. Create a record type Product with fields product_id, product_name and stock
quantity. (4)
2. Create an array of type Product of size 10. (2)
3. Populate the array with distinct values. (4)
4. Find the product with the maximum stock and minimum stock. (5)
5. Create a function named as getUserInput which takes no parameter. It takes
input (char / varchar2 type) from user. If the input contains any non-alphabetic
character, the function will prompt the user to enter valid input and keeps on
looping. The function returns the valid input in the end. (10)
6. Use this getUserInput function in a Procedure named as “Find_Employee” which
takes input from user using the above function and find the employee/s with that
name. Use Cursors for handling more than one rows. Display all details of the
employee/s. Also use appropriate exceptions in case of “No data found”. (10)