PROCEDURE SALARY_DIFF
IS
cursor bonus_salary is
SELECT
first_name,
last_name,
salary
FROM bonus
order by salary desc;
type bonus_salary_rec_type is record (
first_name bonus.last_name%TYPE,
last_name bonus.last_name%TYPE,
salary bonus.salary%TYPE);
bonus_salary_rec bonus_salary_rec_type;
v_diff bonus.salary%TYPE;
v_old bonus.salary%TYPE;
BEGIN
open bonus_salary;
select max(salary) into v_old from bonus;
loop
fetch bonus_salary into bonus_salary_rec;
exit when bonus_salary%notfound;
v_diff := bonus_salary_rec.salary - v_old;
-- dbms_output.put_line(v_last_name||' '||v_salary||' '||v_diff);
v_old := bonus_salary_rec.salary;
update bonus set difference = v_diff where
first_name = bonus_salary_rec.first_name and
last_name = bonus_salary_rec.last_name;
end loop;
close bonus_salary;
END; -- Procedure
Gehaltsunterschied mit reinem Oracle-SQL
select last_name, salary, prior salary-salary from (
select rownum rn , rownum-1 rnm, last_name, salary from (
select last_name, salary from employees order by salary desc)
) connect by prior rn = rnm