lunes, 5 de septiembre de 2011

contar cuantos empleados hay por cada departamento :
Creamos un atributo en la tabla departments :
ALTER table DEPARTMENTS add TotEmplexDepartamento number(100)
Ahora procedo a realizar el cursor :
Declare cursor
miCursor is
select e.department_id, count(p.employee_id) as Empleados
from Departments e, Employees p
where p.department_id = e.department_id
group by p.department_id;
vnumdepartamento employees.employee_id%type;
vtotempleados employees.employee_id%type;
begin
open micursor;
loop
fetch micursor into vnumdepartamento,vtotempleados;
exit when micursor%notfound;
update DEPARTMENTS set TotEmplexDepartamento= vtotempleados 
where department_id= vnumdepartamento
end loop;
close micursor;
End;

No hay comentarios.:

Publicar un comentario