-- ITERATE = do loop again CREATE PROCEDURE doiterate(p1 INT) BEGIN label1: LOOP SET p1 = p1 + 1; IF p1 < 10 THEN ITERATE label1; END IF; LEAVE label1; END LOOP label1; SET @x = p1; END -- LEAVE = exit loop CREATE PROCEDURE `test_sp`() BEGIN `my_label`: LOOP SELECT 'looping'; LEAVE `my_label`; END LOOP; SELECT 'out of loop'; END; -- LEAVE = exit proc CREATE PROCEDURE `test_sp`() `my_label`: BEGIN IF @var = 1 THEN LEAVE `my_label`; END IF; DO something(); END `my_label`; CREATE PROCEDURE proc(IN p TINYINT) CONTAINS SQL `whole_proc`: BEGIN SELECT 1; IF p < 1 THEN LEAVE `whole_proc`; END IF; SELECT 2; END; CALL proc(0);
SQL Справочник v0.05 © 2007-2025 Igor Salnikov aka SunDoctor