You are on page 1of 2

SET SERVEROUTPUT ON SIZE 10000;

DECLARE
N INT :=&var;
BEGIN
FOR CONT IN REVERSE 1..N LOOP
DBMS_OUTPUT.PUT_LINE(CONT);
END LOOP;
END;
--WHILE (...)LOOP
--END LOOP;
DECLARE
nombre EMPLOYEES.first_name%TYPE;
cursor c1 is select first_name
from EMPLOYEES;
cursor c2 is select count(*) from employees;
BEGIN
OPEN c2;
OPEN c1;
for cont in 1..c2 loop
FETCH c1 INTO nombre;
DBMS_OUTPUT.PUT_LINE(nombre);
end loop;
CLOSE c2;
CLOSE c1;
END;

DECLARE
nombre EMPLOYEES.first_name%TYPE;
cursor c1 is select first_name
from EMPLOYEES;
BEGIN
OPEN c1;
LOOP
FETCH c1 INTO nombre;
DBMS_OUTPUT.PUT_LINE(nombre);
EXIT WHEN C1%NOTFOUND;
END LOOP;
DBMS_OUTPUT.PUT_LINE(c1%ROWCOUNT
||'Reg. Procesados');
CLOSE c1;
END;

DECLARE
nombre DEPARTMENTS.department_name%TYPE;
cantidad int;
cont int:=&var;
cursor c1 is select d.department_name ,count(*) cant
from departments d,employees e
where d.department_id=e.department_id
group by d.department_name order by 2 desc;
BEGIN
OPEN c1;
for c in 1..cont loop
FETCH c1 INTO nombre,cantidad;
DBMS_OUTPUT.PUT_LINE(c||'.- NOMBRE: '
||nombre||'.-CANTIDAD: '||cantidad);
end loop;
CLOSE c1;
END;

DECLARE
nombree EMPLOYEES.first_name%TYPE;
nombred DEPARTMENTS.department_name%TYPE;
cont int:=&var;
cursor c1 is select e.first_name,d.department_name
from departments d,employees e
where d.department_id=e.department_id;
BEGIN
OPEN c1;
for c in 1..cont loop
FETCH c1 INTO nombree,nombred;

DBMS_OUTPUT.PUT_LINE('------------------------------------------------------');
DBMS_OUTPUT.PUT_LINE(c||'.- NOMBRE EMPLEADO: '||nombree);
DBMS_OUTPUT.PUT_LINE(c||'.- NOMBRE DEPARTAMENTO: '||nombred);

DBMS_OUTPUT.PUT_LINE('------------------------------------------------------');
end loop;
CLOSE c1;
END;

You might also like