﻿ PL/SQL Cursor: Display the name of the employee and increment percentage of salary according to their working experiences - w3resource

# PL/SQL Cursor Exercises: Display the name of the employee and increment percentage of salary according to their working experiences

## PL/SQL Cursor: Exercise-32 with Solution

Write a PL/SQL program to display the name of the employee and increment percentage of salary according to their working experiences.

Sample Solution:

PL/SQL Code:

``````DROP TABLE emp_temp;
CREATE TABLE emp_temp AS
SELECT *
FROM employees;

DECLARE
CURSOR employees_cur IS
SELECT employee_id,
first_name,
Trunc(Months_between(SYSDATE,hire_date) / 12) expr
FROM   emp_temp;

incre_per NUMBER(2);
BEGIN
dbms_output.Put_line('-----------------------------------------------------------');
FOR store_emp_rec IN employees_cur
LOOP
incre_per :=
CASE
WHEN store_emp_rec.expr > 10 THEN
15
WHEN store_emp_rec.expr > 5 THEN
10
ELSE
8
END;
UPDATE emp_temp
SET    salary = salary + (salary * incre_per / 100)
WHERE  employee_id = store_emp_rec.employee_id;
END LOOP;
END;
/

``````

Sample Output:

```SQL> /
Employee ID    Name                     Increment %
----------------------------------------------------
100            Steven                   15
101            Neena                    15
102            Lex                      15
103            Alexander                15
104            Bruce                    10
105            David                    15
106            Valli                    15
107            Diana                    15
108            Nancy                    15
109            Daniel                   15
110            John                     15
111            Ismael                   15
112            Jose Manuel              15
113            Luis                     10
114            Den                      15
...
```

Flowchart:

Improve this sample solution and post your code through Disqus

What is the difficulty level of this exercise?

﻿

Inviting useful, relevant, well-written and unique guest posts