martes, 24 de abril de 2012

Clase 21 de Abril

set serveroutput on;

declare
NO_REGISTRO exception; --declaramos la exception
vtotalCargo integer;
vtotalEmpleados integer;
vtasa numeric(4,1);
vnombreCargo employees.job_id%type;
begin
vnombreCargo := '&IngreseCargo';
select count(*) into vtotalCargo from employees where job_id = vnombreCargo;
select count(*) into vtotalEmpleados from employees;

if vtotalEmpleados = 0 then --gatillamos la exception
Raise NO_REGISTRO;

dbms_output.put_line('El total de empleados con el cargo de ' || vnombreCargo || ' es: ' || vtotalCargo);
dbms_output.put_line('El total de empleados de la compañia es: ' || vtotalEmpleados);

vtasa := round(vtotalCargo / vtotalEmpleados,1);

if vtasa >= 0.3 and vnombreCargo = 'SA_REP' then
dbms_output.put_line('Muchos caciques para tan pocos indios');
end if;
Exception
  when ZERO_DIVIDE then
  dbms_output.put_line('');
  when NO_REGISTRO then
  dbms_output.put_line('No se han encontrado registros para esta busqueda');
  when others then
  dbms_output.put_line('Ha ocurrido un Error del tipo OTHERS');
end;

No hay comentarios:

Publicar un comentario