jueves, 10 de mayo de 2012

09 de Mayo Ejercicio 2 Control 2

set serveroutput on;

declare

cursor crListaEmpleado is
  select FIRST_NAME, LAST_NAME, HIRE_DATE from employees
  order by LAST_NAME;
 
  recEmpleado crListaEmpleado%ROWTYPE;
  cnt integer := 0;
  edad integer;
  msg varchar2(50);

begin
open crListaEmpleado;
fetch crListaEmpleado into recEmpleado;
while crListaEmpleado%FOUND loop
 
  exit when crListaEmpleado%NOTFOUND;
 
  cnt := cnt + 1;
  edad := round((sysdate - recEmpleado.HIRE_DATE)/365);
  if edad <= 25 then
    msg := 'Junior';
  elsif edad > 25 and edad < 40 then
    msg := 'Senior';
  else
    msg := 'Master';
  end if;
dbms_output.put_line(recEmpleado.FIRST_NAME || ' ' || recEmpleado.LAST_NAME || ' ' || msg);
fetch crListaEmpleado into recEmpleado;
end loop;
close crListaEmpleado;
dbms_output.put_line('El total de empleados es: ' || cnt);

exception
  when OTHERS then
  dbms_output.put_line('esta malo');

end;

No hay comentarios:

Publicar un comentario