Examples for business, study, careers, love, and more...
Examples :: MYSQL Examples :: Example of Loop MYSQL Statement

Example of Loop MYSQL Statement

[begin_label:] LOOP
statement_list
END LOOP [end_label]

Example of Mysql Loop


Delimiter $$
CREATE PROCEDURE myProc()
DETERMINISTIC
BEGIN
DECLARE counter INT DEFAULT 0;
simple_loop: LOOP
SET counter=counter+1;
select counter;
IF counter=10 THEN
LEAVE simple_loop;
END IF;
END LOOP simple_loop;
SELECT 'I can count to 10';
END$$