SET SERVEROUTPUT ON;

DECLARE
 v_nb_lignes NUMBER;
BEGIN
 DELETE FROM emp WHERE dep = 10;
 v_nb_lignes := SQL%ROWCOUNT;
 dbms_output.put_line('v_nb_lignes : ' || v_nb_lignes);
 -- ...
END;

-------------------------------------------------------

DECLARE
  v_salaire EMP.sal%TYPE;
  v_total   EMP.sal%TYPE := 0;
  CURSOR c_salaires IS
    SELECT sal
    FROM emp;
BEGIN
  OPEN c_salaires;
  
  LOOP
    FETCH c_salaires INTO v_salaire;
    EXIT WHEN c_salaires%NOTFOUND;
    IF v_salaire IS NOT NULL THEN
      v_total := v_total + v_salaire;
      dbms_output.put_line('salaire : ' || v_salaire);
    END IF;
  END LOOP;
  
  CLOSE c_salaires;
  dbms_output.put_line('total : ' || v_total);
END;

-------------------------------------------------------

DECLARE
  CURSOR c_emp IS
    SELECT sal, dep
    FROM emp;
  v_emp     c_emp%ROWTYPE;
  v_total   v_emp.sal%type := 0;
BEGIN
  OPEN c_emp;
  
  LOOP
    FETCH c_emp INTO v_emp;
    EXIT WHEN c_emp%NOTFOUND;
    IF v_emp.sal IS NOT NULL THEN
      v_total := v_total + v_emp.sal;
      dbms_output.put_line('salaire : ' || v_emp.sal);
    END IF;
  END LOOP;
  
  CLOSE c_emp;
  dbms_output.put_line('total : ' || v_total);
END;

-----------------------------------------------------

DECLARE
  CURSOR c_nom_emp IS
    SELECT nom, adresse
    FROM emp;
BEGIN
  FOR v_emp IN c_nom_emp LOOP
    dbms_output.put_line(
      'Employe : ' || UPPER(v_emp.nom) ||
      ' Ville : '  || v_emp.adresse);
  END LOOP;
END;

-----------------------------------------------------

DECLARE
  CURSOR c(p_dep EMP.dep%TYPE) IS
    SELECT dep, nom
    FROM emp
    WHERE dep = p_dep;
BEGIN
  FOR v_employe IN c(1) LOOP
	  dbms_output.put_line('Dep 1 : ' || v_employe.nom);
	END LOOP;
	FOR v_employe IN c(2) LOOP
	  dbms_output.put_line('Dep 2 : ' ||v_employe.nom);
	END LOOP;
END;
