0
我想在我的項目中使用光標,但它會引發錯誤1064
。請幫我解決問題.....光標在存儲過程中不起作用它拋出1064錯誤
錯誤代碼:1064您的SQL語法錯誤;在行來檢查對應於你的MySQL服務器版本使用附近的正確語法手冊 '聲明光標1 CURSOR FOR SELECT healthinsurancepremium.productid,healthinsuran' 63
我的程序代碼:
CR-EATE DEFINER=`root`@`localhost` PROCEDURE `spGettestOffline` (
IN in_sumassured INT(10),
IN in_age INT(3),
IN in_adult INT(4),
IN in_child INT(4),
IN in_tenure INT(3),
IN in_city VARCHAR(20)
)
BEGIN
DECLARE bDone INT DEFAULT 0;
DECLARE var1 INT ;
DECLARE Var2 INT;
DECLARE Var3 INT;
DECLARE var4 INT;
/* this is the table declaration */
DROP TEMPORARY TABLE IF EXISTS tblResults;
CREATE TEMPORARY TABLE IF NOT EXISTS tblResults (
productid INT,
suminsured INT,
amount INT,
tenent INT
);
/* this is the cursor declaration */
DECLARE curs1 CURSOR FOR SELECT healthinsurancepremium.productid ,healthinsurancepremium.suminsured ,healthinsurancepremium.amount ,healthinsurancepremium.tenure FROM healthinsurancepremium LEFT JOIN `cityspecifichealthpremium` ON `healthinsurancepremium`.`id` >= `cityspecifichealthpremium`.`healthpremiumidmin` AND `healthinsurancepremium`.`id` <= `cityspecifichealthpremium`.`healthpremiumidmax` WHERE (`cityspecifichealthpremium`.`healthpremiumidmax` IS NULL AND `cityspecifichealthpremium`.`healthpremiumidmin` IS NULL) AND healthinsurancepremium.suminsured = in_sumassured AND in_age >=healthinsurancepremium.minage AND in_age <=healthinsurancepremium.maxage AND healthinsurancepremium.adult=in_adult AND healthinsurancepremium.child=in_child ;
/* this is the cursor looping */
DECLARE CONTINUE HANDLER FOR NOT FOUND SET bDone = 1;
OPEN curs1;
read_loop: LOOP
FETCH curs1 INTO var1,var2,var3,var4;
INSERT INTO tblResults VALUES (var1,var2, var3,var4);
IF (bDone = 1) THEN
LEAVE read_loop;
END IF;
END LOOP;
CLOSE curs1;
SELECT * FROM tblResults;
END$$
我認爲這個問題屬於遊標聲明部分....但是我沒有找到任何東西
謝謝......但後來,我應該把創建臨時錶款..光標或在裏面? – user3168097
@ user3168097:您可以在所有'DECLARE'語句後面加上。 –