Advertisement
xlujiax

SQL

Oct 19th, 2018
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PL/SQL 0.60 KB | None | 0 0
  1. SET SERVEROUTPUT ON
  2. DECLARE  
  3. cod_Dep DEPARTMENTS.DEPARTMENT_ID%TYPE;
  4. nam_dep departments.department_name%TYPE;
  5. CURSOR c1 IS SELECT d.Department_id, d.department_name, e.salary
  6. FROM DEPARTMENTS d join employees e
  7. ON d.DEPARTMENT_ID=e.DEPARTMENT_ID;
  8.  
  9. salary employees.salary%TYPE;
  10.  
  11. BEGIN
  12. salary :=0;
  13. cod_dep := 20;
  14. FOR i IN c1 LOOP
  15. IF cod_dep = i.department_id THEN  
  16.   salary := salary + i.salary;  
  17. END IF;
  18. nam_dep := i.department_name;
  19. END LOOP;  
  20. DBMS_OUTPUT.put_line('El departamento ' || nam_dep || ' de codigo: ' || cod_dep ||' tiene como suma de salario: ' || salary );
  21. END;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement