DELIMITER $$
CREATE PROCEDURE `prt`()
BEGIN
END$$
DELIMITER ;
CREATE PROCEDURE `prt`()
BEGIN
DECLARE m_end,m_id INT DEFAULT 0;
DECLARE cur CURSOR FOR SELECT id FROM tt01;
DECLARE CONTINUE HANDLER FOR NOT FOUND
BEGIN
SET m_end = 1;# remove warning "No data - zero rows fetched, selected, or processed"
SELECT 1 INTO @t FROM (SELECT 1) AS t;
END;
/*
CREATE TABLE `tt01` ( `id` int(11) NOT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8;
*/
OPEN cur;
w1:WHILE 1 DO
FETCH cur INTO m_id;IF m_end =1 THEN
LEAVE w1;
END IF;SELECT m_id;
END WHILE;
CLOSE cur;
END$$
DELIMITER ;
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/26250550/viewspace-1311410/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/26250550/viewspace-1311410/