CREATE TABLE INPUT ( NUM INT );
INSERT INTO INPUT VALUES (1);
CREATE TABLE OUTPUT ( NUM INT );
DELIMITER //
CREATE PROCEDURE TEST_LOOP()
BEGIN
DECLARE NUMBER INT;
DECLARE DONE TINYINT DEFAULT 0;
DECLARE REC CURSOR FOR SELECT NUM FROM INPUT;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET DONE = 1;
DELETE FROM OUTPUT;
OPEN REC;
L: LOOP
FETCH REC INTO NUMBER;
IF DONE = 1 THEN
LEAVE L;
END IF;
INSERT INTO OUTPUT VALUES (NUMBER);
END LOOP;
CLOSE REC;
END //
DELIMITER ;
然后我运行CALL TEST_LOOP();
,程序按预期运行(OUTPUT 表中的一条记录)但产生警告说:
No data - zero rows fetched, selected, or processed.
警告来自哪里?