I have the next procedure:
BEGIN
  DECLARE retribAn INTEGER DEFAULT 0; 
  DECLARE cPost INTEGER(11);     
  DECLARE done INT DEFAULT 0;
  DECLARE curTipo CURSOR FOR
          SELECT RETRIBUCION_ANUAL*1.05 AS RET_AN
          FROM EMPLEADOS  
          WHERE ID_CPOSTAL%2=0;
  DECLARE CONTINUE HANDLER FOR NOT FOUND SET done=1;
  OPEN curTipo;
  REPEAT
    FETCH curTipo INTO retribAn, cPost;
    IF NOT done THEN       
      UPDATE EMPLEADOS 
      SET RETRIBUCION_ANUAL=retribAn  
      WHERE ID_CPOSTAL%cPost;  
    END IF;
  UNTIL done END REPEAT;
  CLOSE curTipo;    
END
when I execute it, sql manager outputs:
Incorrect number of FETCH variables
I do not understand why.
I'm a rookie =D in mysql, and sorry for my English.
Thanks
you are selecting only one column in your cursor query and fetching data into two variables in FETCH
Try this
BEGIN
  DECLARE retribAn INTEGER DEFAULT 0; 
  DECLARE cPost INTEGER(11);     
  DECLARE done INT DEFAULT 0;
  DECLARE curTipo CURSOR FOR
          SELECT RETRIBUCION_ANUAL*1.05 AS RET_AN
          FROM EMPLEADOS  
          WHERE ID_CPOSTAL%2=0;
  DECLARE CONTINUE HANDLER FOR NOT FOUND SET done=1;
  OPEN curTipo;
  REPEAT
    FETCH curTipo INTO retribAn; --remove cPost here
    IF NOT done THEN       
      UPDATE EMPLEADOS 
      SET RETRIBUCION_ANUAL=retribAn  
      WHERE ID_CPOSTAL%cPost = 0;  --change this to value you want to check
    END IF;
  UNTIL done END REPEAT;
  CLOSE curTipo;    
END
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With