Documentos de Académico
Documentos de Profesional
Documentos de Cultura
OFICIO: XXXXX
OFICIO: XXXXX
OFICIO: XXXXX
OFICIO: XXXXX
SOLUCIÓN:
declare
cursor c1 is select * from depart;
cursor c2(dep number) is select * from emple where dept_no = dep order by oficio;
regdep c1%rowtype;
regemp c2%rowtype;
v_oficio varchar2(10);
mediasal number(8,2);
sumasal number(8,2);
con number(5);
begin
open c1;
fetch c1 into regdep;
While C1%Found Loop
dbms_output.Put_Line('');
dbms_output.Put_Line(' NUM DEPART: '|| regdep.dept_no ||' NOMBRE DEPART: '||
regdep.dnombre ||' LOCALIDAD: '|| regdep.loc);
open c2(regdep.dept_no);
fetch c2 into regemp;
if c2%notfound then
dbms_output.Put_Line(' DEPARTAMENTO SIN EMPLEADOS.');
dbms_output.Put_Line(' ---------------------------');
else
con:=0;
sumasal:=0;
v_oficio := regemp.oficio;
dbms_output.Put_Line('');
dbms_output.Put_Line('OFICIO: ' || v_oficio);
dbms_output.Put_Line('');
dbms_output.Put_Line(' APELLIDO SALARIO FECHA_ALT COMISIÓN');
dbms_output.Put_Line(' --------------- ---------- ---------- --------');
While C2%Found Loop
if(regemp.oficio <> v_oficio) then
Mediasal := Sumasal/Con;
Dbms_Output.Put_Line('');
Dbms_Output.Put_Line(' TOTAL SALARIO: ' || Sumasal);
dbms_output.Put_Line(' MEDIA SALARIO: ' || Mediasal );
v_oficio := regemp.oficio;
con:=0;
sumasal:=0;
dbms_output.Put_Line('');
dbms_output.Put_Line('OFICIO: ' || v_oficio);
dbms_output.Put_Line('');
dbms_output.Put_Line(' APELLIDO SALARIO FECHA_ALT COMISIÓN');
dbms_output.Put_Line(' ----------- ------- ---------- --------');
End If;
dbms_Output.Put_Line(' ' ||rpad(Regemp.Apellido,12)|| ' ' ||
rpad(to_char(regemp.salario),8) ||' '||
rpad(to_char(regemp.fecha_alt),10) || ' '||
rpad(to_char(nvl(regemp.comision, 0)),8));
sumasal := sumasal + regemp.salario;
con :=con + 1;
fetch c2 into regemp;
End Loop;
Mediasal := Sumasal/Con;
Dbms_Output.Put_Line('');
Dbms_Output.Put_Line(' TOTAL SALARIO: ' || Sumasal);
dbms_output.Put_Line(' MEDIA SALARIO: ' || Mediasal );
End If;
Close C2;
fetch c1 into regdep;
end loop; --depart
close c1;
end;
SALIDA:
NUM DEPART: 10 NOMBRE DEPART: CONTABILIDAD LOCALIDAD: SEVILLA
OFICIO: DIRECTOR
OFICIO: EMPLEADO
OFICIO: PRESIDENTE
OFICIO: ANALISTA
OFICIO: DIRECTOR
OFICIO: EMPLEADO
OFICIO: DIRECTOR
OFICIO: EMPLEADO
OFICIO: VENDEDOR