日期:2014-05-16 浏览次数:21007 次
[begin_label:] LOOP statement_list END LOOP [end_label]
DELIMITER$$ CREATE PROCEDURE pro_loop(p1 INT) BEGIN label1: LOOP SET p1 = p1 + 1; IF p1 < 10 THEN SELECT p1 AS result; ITERATE label1; END IF; SELECT 'END IF' AS result; LEAVE label1; END LOOP label1; SET @x = p1; SELECT @x as result; END$$
[begin_label:] WHILE search_condition DO statement_list END WHILE [end_label]
DELIMITER$$ DROP PROCEDURE IF EXISTS pro_while$$ CREATE PROCEDURE pro_while ( i INT ) BEGIN DECLARE j INT DEFAULT 1; WHILE j < i DO SELECT j AS result; SET j = j + 1; END WHILE; END$$
[begin_label:] REPEAT statement_list UNTIL search_condition END REPEAT [end_label]
DELIMITER$$ DROP PROCEDURE IF EXISTS pro_repeat$$ CREATE PROCEDURE pro_repeat(p1 INT) BEGIN SET @X = 0; REPEAT SELECT @X AS result; SET @X = @X + 1; UNTIL @X > p1 END REPEAT; END$$