下面的代碼只循環一次遊標,在一個循環中,它將product_name和list_price設置爲null。我已經運行了SELECT語句(CURSOR的那個),它返回4個結果。我不確定如何或爲何它在所有4次不循環,爲什麼,它的單迴路,它是幹什麼的,是不是使用PRODUCT_NAME和list_price第一記錄的值MySQL CURSOR沒有獲取所需的行
DROP PROCEDURE IF EXISTS test;
DELIMITER //
CREATE PROCEDURE test()
BEGIN
DECLARE retString VARCHAR(1000);
DECLARE rowNotFound TINYINT DEFAULT FALSE;
DECLARE product_name VARCHAR(255);
DECLARE list_price DECIMAL(10,2);
DECLARE prodCursor CURSOR FOR
SELECT product_name, list_price FROM products WHERE list_price > 700 ORDER BY list_price DESC;
DECLARE CONTINUE HANDLER FOR NOT FOUND
SET rowNotFound = TRUE;
OPEN prodCursor;
WHILE rowNotFound = FALSE DO
FETCH prodCursor INTO product_name, list_price;
SET retString = CONCAT(retString, '"', product_name, '","' , list_price, '"|');
END WHILE;
CLOSE prodCursor;
SELECT retString AS 'Message';
END//
DELIMITER ;
CALL test();