我很新的MySQL的存儲過程,並得到了以下錯誤:MySQL存儲過程不起作用
1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DECLARE v_lang TINYINT(1) DEFAULT '1'; DECLARE cursor_lang CURSOR FOR SELECT `l' at line 7
當試圖建立這個存儲過程:
DELIMITER //
CREATE PROCEDURE UpdateUser(IN p_uid INT(11))
BEGIN
DECLARE v_last_login TIMESTAMP DEFAULT '2012-01-01 00:00:00' ;
SELECT `last_login` INTO v_last_login FROM `user` WHERE `id`= p_uid;
DECLARE v_lang TINYINT(1) DEFAULT '1';
DECLARE cursor_lang CURSOR FOR SELECT `l_id` INTO v_lang FROM `user_lang` WHERE `user_id` = p_uid LIMIT 0 , 5;
DECLARE no_more_l TINYINT(1) DEFAULT 0;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET no_more_l = 1;
OPEN cursor_lang;
FETCH cursor_lang INTO v_lang_str;
REPEAT
UPDATE user SET `last_login`=CURRENT_TIMESTAMP() WHERE `id`=p_uid AND `l_id` = v_lang_str;
UNTIL no_more_l = 1
END REPEAT;
CLOSE cursor_lang;
END //
DELIMITER ;
做什麼,我做錯了?
你爲什麼使用遊標? – 2012-03-23 13:32:32