*DELIMITER //
create procedure test(OUT l_out INT)
begin
DECLARE done INT DEFAULT FALSE;
declare l_sno INT default 0;
declare a INT default 0;
declare b INT default 0;
declare cur_1 cursor for select sno,interest from temp t where x_coord between 55 and 60 for update of interest;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
open cur_1;
read_loop: LOOP
fetch cur_1 into a,b;
if done then
Leave read_loop;
end if;
set l_sno=l_sno+1;
update temp set interest =1 where CURRENT OF cur_1;
END LOOP;
close cur_1;
set l_out=l_sno;
end //
;*
错误:
1064-您的SQL语法有错误;请检查与MySQL服务器版本相对应的手册,以获得在“关注点”附近使用的正确语法;在第7行声明“未找到”的继续处理程序SET done=TRUE;open cur_1;”
1064-您的SQL语法有错误;请检查与MySQL服务器版本对应的手册,以获取在第16行“OF cur_1;END LOOP;close cur_1;set l_out=l_sno;END”附近使用的正确语法
最佳答案
在我看来,您来自另一种SQL,比如DB2——这些工作都完成了。
引自http://dev.mysql.com/doc/refman/5.0/en/cursor-restrictions.html
游标是只读的;不能使用游标更新行。
未实现UPDATE WHERE CURRENT OF和DELETE WHERE CURRENT OF,因为不支持可更新的游标。
所以我想你不能这样做,你必须指定一个类似mysql的where子句。
关于mysql - MYSQL游标所在的当前,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10555219/