Está en la página 1de 4

Usando las tablas emple y depart.

Visualizar por cada departamento el número de departamento , el nombre del


departamento y la localidad y de cada oficio de ese departamento los
empleados que tiene (apellido, salario, y fecha de alta), después mostrar
el número total de empleados con ese oficio y la media de salario de los
empleados de ese oficio.

Por departamento y oficio debe salir el siguiente informe:


NUM DEPART: xxxx NOMBRE DEPART: xxxx LOCALIDAD: xxxxxxx

OFICIO: XXXXX

APELLIDO SALARIO FECHA_ALT COMISIÓN


--------------- --------------- ---------------- ----------------
xxxxxxx xxxxxxxx xxxxxx xxxxxxxxxxx
xxxxxxx xxxxxxxx xxxxxx xxxxxxxxxxx

TOTAL SALARIO: xxx


MEDIA SALARIO: xxxx

OFICIO: XXXXX

APELLIDO SALARIO FECHA_ALT COMISIÓN


--------------- --------------- ---------------- ----------------
xxxxxxx xxxxxxxx xxxxxx xxxxxxxxxxx
xxxxxxx xxxxxxxx xxxxxx xxxxxxxxxxx

TOTAL SALARIO: xxx


MEDIA SALARIO: xxxx

NUM DEPART: xxxx NOMBRE DEPART: xxxx LOCALIDAD: xxxxxxx

OFICIO: XXXXX

APELLIDO SALARIO FECHA_ALT COMISIÓN


--------------- --------------- ---------------- ----------------
xxxxxxx xxxxxxxx xxxxxx xxxxxxxxxxx
xxxxxxx xxxxxxxx xxxxxx xxxxxxxxxxx

TOTAL SALARIO: xxx


MEDIA SALARIO: xxxx

OFICIO: XXXXX

APELLIDO SALARIO FECHA_ALT COMISIÓN


--------------- --------------- ---------------- ----------------
xxxxxxx xxxxxxxx xxxxxx xxxxxxxxxxx
xxxxxxx xxxxxxxx xxxxxx xxxxxxxxxxx

TOTAL SALARIO: xxx


MEDIA SALARIO: xxxx

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

APELLIDO SALARIO FECHA_ALT COMISIÓN


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

CEREZO 2885 09/06/91 0

TOTAL SALARIO: 2885


MEDIA SALARIO: 2885

OFICIO: EMPLEADO

APELLIDO SALARIO FECHA_ALT COMISIÓN


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

SANCHEZ 1690 23/01/92 0


MUÑOZ 1690 23/01/92 0

TOTAL SALARIO: 3380


MEDIA SALARIO: 1690

OFICIO: PRESIDENTE

APELLIDO SALARIO FECHA_ALT COMISIÓN


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

REY 4380 17/11/91 0

TOTAL SALARIO: 4380


MEDIA SALARIO: 4380

NUM DEPART: 20 NOMBRE DEPART: INVESTIGACION LOCALIDAD: MADRID

OFICIO: ANALISTA

APELLIDO SALARIO FECHA_ALT COMISIÓN


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

GIL 3000 09/11/91 0

TOTAL SALARIO: 3000


MEDIA SALARIO: 3000

OFICIO: DIRECTOR

APELLIDO SALARIO FECHA_ALT COMISIÓN


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

JIMENEZ 2900 02/04/91 0


FERNANDEZ 3000 03/12/91 0

TOTAL SALARIO: 5900


MEDIA SALARIO: 2950

OFICIO: EMPLEADO

APELLIDO SALARIO FECHA_ALT COMISIÓN


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

ALONSO 1430 23/09/91 0


SANCHEZ 1040 17/12/90 0

TOTAL SALARIO: 2470


MEDIA SALARIO: 1235

NUM DEPART: 30 NOMBRE DEPART: VENTAS LOCALIDAD: BARCELONA

OFICIO: DIRECTOR

APELLIDO SALARIO FECHA_ALT COMISIÓN


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

NEGRO 3005 01/05/91 0

TOTAL SALARIO: 3005


MEDIA SALARIO: 3005

OFICIO: EMPLEADO

APELLIDO SALARIO FECHA_ALT COMISIÓN


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

JIMENO 1335 03/12/91 0

TOTAL SALARIO: 1335


MEDIA SALARIO: 1335

OFICIO: VENDEDOR

APELLIDO SALARIO FECHA_ALT COMISIÓN


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

TOVAR 1350 08/09/91 0


SALA 1625 22/02/91 650
ARROYO 1500 20/02/90 390
MARTIN 1600 29/09/91 1020

TOTAL SALARIO: 6075


MEDIA SALARIO: 1518,75
NUM DEPART: 40 NOMBRE DEPART: PRODUCCION LOCALIDAD: BILBAO
DEPARTAMENTO SIN EMPLEADOS.
---------------------------

También podría gustarte