I need to display employee's position, employee's name, and the average salary from 'sales' department, after they are being updated. The condition of update are...if the employee is also a manager, then increase salary by 30% (salary+(salary*30%)), but if the employee's job is a 'sales representative' then increase salary by 50%.
The example output:
Manager John Russell 27817
Manager Karen Partners27167
Sales Jonathon Taylor 22517
This is my code so far
declare
cursor dept_detail is
select employee_id,first_name,salary,job_id
from employees
where department_id=(select department_id from departments where department_name='Sales');
TYPE record_type IS RECORD (
dept_id employees.employee_id%TYPE,
dept_name employees.first_name%TYPE,
dept_sal employees.salary%TYPE,
dept_job employees.job_id%TYPE);
dept_record record_type;
begin
OPEN dept_detail;
LOOP
FETCH dept_detail INTO dept_record;
EXIT WHEN dept_detail%NOTFOUND;
dbms_output.put_line (dept_record.dept_name||' '||dept_record.avg(dept_sal));
if dept_record.dept_job=15 or dept_record.dept_job=16 then
update employees set salary = salary+(salary*.50);
elsif dept_record.dept_id=(select distinct(manager_id) from employees) then
update employees set salary = salary+(salary*.30);
end if;
end loop;
end;
/
The problem is oracle does not allow a subquery in if condition, and i also cannot display average salary. And also, how do you give a condition to dbms_output.put_line for the 'manager' or 'sales' display