User Tools

Site Tools


kurs:p_salary_cursor

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

kurs:p_salary_cursor [2014/09/10 21:22] (current)
Line 1: Line 1:
 +<​code>​
 +CREATE OR REPLACE ​
 +PROCEDURE p_salary_cursor
 +   IS
 +cursor c_emp_sal is
 +  SELECT
 +      employees.last_name,​
 +      employees.salary
 +    FROM employees
 +      order by employees.salary desc;
  
 +   ​v_old_name ​  ​employees.last_name%TYPE;​
 +   ​v_new_name ​  ​employees.last_name%TYPE;​
 +   ​v_new_salary employees.salary%TYPE;​
 +   ​v_old_salary employees.salary%TYPE;​
 +   ​v_diff ​      ​number(30);​
 +
 +BEGIN
 +   open c_emp_sal;
 +
 +   fetch c_emp_sal into v_old_name, v_old_salary;​
 +   for i in 1..10 loop
 +     fetch c_emp_sal into v_new_name, v_new_salary;​
 +       ​v_diff := v_old_salary-v_new_salary;​
 +       ​dbms_output.put_line(v_new_name || ' verdient um ' ||
 +                            v_diff || ' weniger als ' ||
 +                            v_old_name);​
 +     ​v_old_name ​  := v_new_name;
 +     ​v_old_salary := v_new_salary;​
 +   end loop;
 +   close c_emp_sal;
 +END; -- Procedure
 +/
 +</​code>​
kurs/p_salary_cursor.txt ยท Last modified: 2014/09/10 21:22 (external edit)