BEGIN
DECLARE finished INT DEFAULT 0;
DECLARE v_year INT;
DECLARE month INT DEFAULT 1;
DECLARE year_cursor CURSOR FOR SELECT Year FROM YEAR;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET finished := 1;
OPEN year_cursor;
YEARLOOP: LOOP
FETCH year_cursor into v_year;
IF finished=1 THEN
LEAVE YEARLOOP;
END IF;
MONTHLOOP: LOOP
IF month > 12 THEN
LEAVE MONTHLOOP;
END IF;
SELECT CONCAT(v_year,'-',month,'-%');
SET month = month +1;
END LOOP;
END LOOP;
CLOSE year_cursor;
END
在上面的过程中,只获取了year表的第一行,然后外部循环退出,为什么会这样,是不是我没有正确使用游标或其他东西。需要帮助。