Question

This is driving me nuts.

 CREATE DEFINER=`root`@`localhost` PROCEDURE `CalcularCRTarea` (Id_Tarea INT, OUT crTarea decimal(12, 4))
    DETERMINISTIC
BEGIN
  DECLARE done BOOLEAN DEFAULT FALSE;
  DECLARE _id BIGINT UNSIGNED;
  DECLARE cur CURSOR FOR SELECT Id FROM Tarea_Frente where Id_Item_Tarea = Id_Tarea;
  DECLARE CONTINUE HANDLER FOR NOT FOUND SET done := TRUE;
  OPEN cur;
  testLoop: LOOP
    FETCH cur INTO _id;
    IF done THEN
      LEAVE testLoop;
    ELSE 
        CALL CalcularCRFrente(_id, @suma);
        SET crTarea = crTarea + @suma;
    END IF;
  END LOOP testLoop;

  CLOSE cur;      
END;

phpmyadmin returns me

MySQL said: Documentation

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 4 

that would be the line

  DECLARE done BOOLEAN DEFAULT FALSE;

what's wrong here ? I tried with several minor changes and I'm getting always the same error. I checked the documentation and I'm not seeing what's the syntax error. I know this is a silly error but I'm stucked with this like a half an hour. Is a cursor that iterates each row and executes a stored procedure for each one; I've done it with stored functions (and it worked like a charm) but at the time to publish in the server I saw that my shared hosting doesn't suppor stored functions, only stored procedures :( So it's the best way I've found.

Était-ce utile?

La solution

You are missing custom delimiter instruction.

As you missed it, engine tried to compile the statements when it found the first default statement terminator, the semicolon ;. And hence the exception.

Place your entire routine in between:

-- define the delimiter
delimiter //


--- place here your stored procedure

-- and lastly following line
//

-- reset the delimiter
delimiter ;
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top