在CONTINUE HANDLER上禁用EXECUTE语句效果(mysql 5.5)

时间:2013-11-11 14:21:55

标签: mysql sql mysql-5.5

我在mysql上有一个sql代码:

DELIMITER //
CREATE PROCEDURE proc()
main_block: BEGIN
 DECLARE is_finished BOOLEAN DEFAULT FALSE;
 DECLARE row_name VARCHAR(50) DEFAULT FALSE;
 DECLARE row_id INT DEFAULT FALSE;
 DECLARE cur CURSOR FOR SELECT `ID`, `Name` FROM `mytable`;
 DECLARE CONTINUE HANDLER FOR NOT FOUND SET is_finished = TRUE;

 OPEN cur;
 my_loop: REPEAT 
  FETCH cur INTO row_id, row_name;

  IF row_id IS NULL THEN
   LEAVE main_block;
  END IF;

  SET @query = concat('SELECT `ID` INTO @msg_id from ', row_name, '_msgs');
  PREPARE run_query FROM @query;
  EXECUTE run_query;
  DEALLOCATE PREPARE run_query;

  ...

 UNTIL is_finished
 END REPEAT my_loop;
 CLOSE cur;
END;
END //

mytable包含三行,因此Repeat-Until应该可以运行三轮,但在EXECUTE run_query; DEALLOCATE PREPARE run_query; is_finished获得TRUE后,循环在完成第一轮后结束。

如何在EXECUTE变量上禁用is_finished的效果?

0 个答案:

没有答案