2011-11-14 88 views
12

什麼是mysql的while循環中的中斷的等價物?mysql while while循環相當於

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

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

感謝

回答

23

得到它。

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; 
13

您可能會感興趣的REPEAT循環:

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