CREATE PROCEDURE loop_test2()
BEGIN
DECLARE aid VARCHAR(36);
-- 遍历数据结束标志
DECLARE done INT DEFAULT FALSE;
DECLARE rep CURSOR FOR SELECT id FROM test_table;
--NOT FOUND和 SQLSTATE '02000'是等价的
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
OPEN rep;
loop_1:LOOP
--如果游标查出来是多个值,fetch就可以into给多个变量
FETCH rep INTO aid;
IF done THEN #详细看下面解释
LEAVE loop_1;
END IF;
SELECT * FROM test_table WHERE id=aid;
END LOOP;
CLOSE rep;
END //