mysql while循环Break等效

时间:2011-11-14 16:55:29

标签: mysql stored-procedures

什么是mysql的while循环中断的等价物?

  WHILE (ctr < i)
  DO ......

    SET cnt = (SELECT COUNT(*) FROM temp_results WHERE result = "true");
    IF cnt > 0 THEN
      SELECT cnt;
      BREAK;
    END IF;

由于

2 个答案:

答案 0 :(得分:28)

得到了它。

myloop: WHILE (ctr < i)
DO 
   …

   SET cnt = (SELECT COUNT(*) FROM temp_results WHERE result = "true");
   IF cnt > 0 THEN
      SELECT cnt;
      LEAVE myloop;
   END IF;
END WHILE myloop;

答案 1 :(得分:15)

您可能对REPEAT循环感兴趣:

REPEAT  
    SET cnt = (SELECT COUNT(*) FROM temp_results WHERE result = "true");
UNTIL cnt > 0 
END REPEAT;