0

i have a problem in my procedure...in this case i want to raisy the salary to employees(Empleado) that have been working 5 years or more inn the store "Bodega"(...sorry about my english,i speak spanish XD). First, i was thinking about select the ID's of all the employees that satisfy the condition (in a cursor) and then compare them to the ID'S in the EMPLEADO TABLE, if the same(the ID'S) then UPDATE the salary...it doesn't work with the IF - END IF (i put in COMMENTS) but without it. needing help...i am doing something wrong but dont know what it is.

CREATE OR REPLACE PROCEDURE aumento_empleado(idBodega IN CHAR)IS

CURSOR c_empl IS SELECT E.idEmpleado 
             FROM Empleado E, Bodega B
             WHERE( MONTHS_BETWEEN(sysdate,E.fecha_contrato)>=5*12 
                    AND E.id_Bodega=B.id_Bodega 
                    AND B.id_Bodega=idBodega); 

idEmpl Char(8);
NO_EMP EXCEPTION;

 BEGIN

 OPEN c_empl;   

LOOP    
FETCH c_empl INTO idEmpl;
EXIT WHEN c_empl%notfound;

  IF c_empl%ROWCOUNT=0 THEN
      RAISE NO_EMP;
  END IF;   

--IF (idEmpl=Empleado.idEmpleado) THEN  
  UPDATE Empleado
  SET Empleado.Sueldo=Empleado.Sueldo + Empleado.Sueldo*0.05;   
--END IF;


END LOOP;   

CLOSE c_empl;

EXCEPTION
   WHEN NO_EMP THEN
         dbms_output.put_line('No hay empleados que cumplan con las condiciones pedidas para la bonificacion' ) ;

   WHEN OTHERS THEN 
     dbms_output.put_line('Error: hubo un error durante la ejecucion del procedimiento' ) ;


END aumento_empleado;
3
  • 1
    Are you required to use a proc for this for an assignment or something? The proc is really far too complicated for the task. Commented Jun 29, 2013 at 16:45
  • Indeed - this is a single UPDATE query; SP is heavily overkill Commented Jun 29, 2013 at 16:46
  • 1
    I suspect you need to modify your UPDATE statement to something like UPDATE Empleado SET Empleado.Sueldo=Empleado.Sueldo + Empleado.Sueldo*0.05 WHERE EMPLEADO.idEMPLEADO=idEmpl. And please don't apologize - your English is a lot better than my Spanish. :-) Share and enjoy. Commented Jun 29, 2013 at 18:46

1 Answer 1

4

This single statement should work for your purpose

    UPDATE Empleado E
  SET E.Sueldo=E.Sueldo + E.Sueldo*0.05
  WHERE MONTHS_BETWEEN(sysdate,E.fecha_contrato)>=5*12 
  AND E.id_Bodega IN (SELECT B.id_Bodega FROM Bodega B)

Avoid using loops where they are not absolutely required.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.