Update within a mysql function

Asked

Viewed 175 times

2

I have to do a process to perform an update on a given table field.

I created a function in mysql. But within this function would need to perform an update, but the non-accepted function would have some way to perform this procedure?

The error that appears is as follows:

Cant update table T043 in stored Function/Trigger because it is already used by statement which Invoked this stored Function/Trigger

Follow the function I created

CREATE DEFINER=`hardness`@`%` FUNCTION `T059_PAC_Fornecedor_Multiplo`(
xT043_Id int(11),
xT043_Qtd int(11),
xT059_T010_Id int(11)) RETURNS int(11)
BEGIN    
   DECLARE xPacQtd INT DEFAULT 0;  
   DECLARE xCount INT DEFAULT 0; 
   DECLARE xCountResult INT DEFAULT 0; 
   SET xPacQtd = T059_PAC_Fornecedor(xT043_Id, xT059_T010_Id);

   IF ((xT043_Qtd % xPacQtd) = 0) THEN
       return xT043_Qtd;
   END IF;

   sloop:LOOP
     SET xCount=xCount+1;
     SET xCountResult = (xPacQtd*xCount);

     IF xCountResult > xT043_Qtd THEN
        UPDATE T043 SET T043_QUANTIDADE = xCountResult WHERE T043_Id = xT043_Id;
        LEAVE sloop;
     END IF;
   END LOOP sloop;

   RETURN xCountResult;
END
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.