Está en la página 1de 3

Materia: INF-272

Docente: Jose Luis Zeballos

Nombre: Elas Castao Maydana


Fecha: 8 de Octubre de 2013

Practica Cursores
Ejercicio 1
Factura Cliente
Idcliente: #####
Nombre: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Costo de hospedaje
#####
Servicio utilizados
xxxxxxxxxxxxxxxxxxxxx
#####
xxxxxxxxxxxxxxxxxxxxx
#####
xxxxxxxxxxxxxxxxxxxxx
#####
xxxxxxxxxxxxxxxxxxxxx
#####
TOTAL
#######

declare
xhIc number;
xhtot number;
xsIc number;
xsDes varchar2(35);
xsCos number;
cursor cliente is (select * from cliente);
xCli cliente%rowtype;
cursor habitacin is (select idcliente, sum (costoHab) as totHab
from (select ha.idcliente, ha.idhabitacion,
trunc((sysdate - ha.fechaingreso) * h.costo) as costoHab
from habita ha
left join (select idhabitacion , costo from
habitacion)h on h.idhabitacion = ha.idhabitacion
)
where idcliente = xCli.idcliente
group by idcliente);
cursor servicio is (select ha.idcliente, sc.descripcion, sc.costoServ
from habita ha
left join (select hs.idhabitacion, ser.descripcion,
(hs.tiempo * ser.costo) costoServ
from hab_ser hs
left join (select idservicio, costo, descripcion from
servicio)ser on ser.idservicio = hs.idservicio
)sc on sc.idhabitacion = ha.idhabitacion
where idcliente = xCli.idcliente);
tot number;
begin
dbms_output.put_line('
FACTURA CLIENTE');
tot := 0;
open cliente;
tot := 0;
loop
fetch cliente into xCli;
exit when cliente%notfound;
dbms_output.put_line('idCliente: '||xcli.idcliente);
dbms_output.put_line('Nombre: '||xCli.nombre);
open habitacin;
loop
fetch habitacin into xhIc, xhtot;
exit when habitacin%notfound;
dbms_output.put_line('Costo Hospedaje: '||xhtot);
tot:=tot+xhtot;
end loop;
close habitacin;
open servicio;
loop
fetch servicio into xsIc, xsDes, xsCos;
exit when servicio%notfound;

dbms_output.put_line(xsDes ||' '||xsCos);


tot := tot + xsCos;
end loop;
close servicio;
dbms_output.put_line('TOTAL:
dbms_output.put_line(' **** ');
dbms_output.put_line(' **** ');
tot := 0;

'||tot);

end loop;
close cliente;
end

Ejercicio 2
HOSPEDADOS POR HABITACION
IDHABITACION: #####
CLIENTES
xxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxx
TOTAL: DOS huspedes
IDHABITACION:
#####
CLIENTES
xxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxx
TOTAL: TRES huspedes
IDHABITACION:
#####
CLIENTES
TOTAL: CERO huspedes
...
...

declare
cursor hab is(select h.idhabitacion, nvl(ca.Cantidad,0) as Cantidad
from habitacion h
left join (select idhabitacion, count(idcliente) as Cantidad
from habita
group by idhabitacion)ca on ca.idhabitacion =
h.idhabitacion
);
xh hab%rowtype;
cursor cli is(select ha.idhabitacion, c.nombre
from habita ha
left join (select idcliente, nombre from cliente)c on ha.idcliente
= c.idcliente
where ha.idhabitacion = xh.idhabitacion
);
xc cli%rowtype;
lit varchar2(20) default 'cero';
begin
dbms_output.put_line('
HOSPEDADOS POR HABITACION');
dbms_output.put_line('------------------------------------------------');
open hab;
loop
fetch hab into xh;
exit when hab%notfound;

CASE
WHEN xh.Cantidad = 0 THEN
WHEN xh.Cantidad = 1 THEN
WHEN xh.Cantidad = 2 THEN
WHEN xh.Cantidad = 3 THEN
WHEN xh.Cantidad = 4 THEN
ELSE lit := 'Numero Grande';

lit
lit
lit
lit
lit

:='Cero';
:='Uno';
:='Dos';
:='Tres';
:='Cuatro';

END case;
dbms_output.put_line('IDHABITACION: '||xh.idhabitacion);
dbms_output.put_line('CLIENTES: ');
open cli;
loop
fetch cli into xc;
exit when cli%notfound;
dbms_output.put_line('

'||xc.nombre);

end loop;
close cli;
dbms_output.put_line('TOTAL: '||lit||' Huespedes');
dbms_output.put_line('------------------------------------------------');
end loop;
close hab;
end

También podría gustarte