myql存储过程,怎么解决这个问题?(查不到记录时,不跳出循环。。。)
本帖最后由 senlinmuvs 于 2012-04-12 09:41:35 编辑
DELIMITER //
DROP PROCEDURE IF EXISTS test//
CREATE PROCEDURE test()
BEGIN
DECLARE results,id2,c INT DEFAULT 0;
DECLARE cur_1 CURSOR FOR SELECT id FROM t1;
DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET results = NULL;
OPEN cur_1;
FETCH cur_1 INTO id2;
WHILE(results IS NOT NULL) DO
#假如这里查询不到记录,则while循环也退出了,有没有什么办法使while循环不会因为这个而退出呢?
SELECT x INTO c FROM t2;
#do some thing...
FETCH cur_1 INTO id2;
END WHILE;
CLOSE cur_1;
END //
DELIMITER ;