2012-05-11 2 views
1
*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 // 
;* 

Ошибка: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 'of interest; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; open cur_1;' at line 7

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 'OF cur_1; END LOOP; close cur_1; set l_out=l_sno; end' at line 16

+0

Я думаю, что эти сообщения об ошибках в значительной степени объясняют все это, не так ли? 'OF INTEREST' и' CURRENT OF' недействительны синтаксис MySQL ... чего вы пытаетесь выполнить? – eggyal

+0

Я хочу обновить на основе текущей позиции курсора – user1389893

+0

Затем удалите 'OF INTEREST' и замените' CURRENT OF cur_1' на любые критерии, указывающие записи, которые вы хотите обновить. – eggyal

ответ

3

смотрит на меня, как вы едете из другого рода SQL, как DB2 - там эти работы.

Цитата http://dev.mysql.com/doc/refman/5.0/en/cursor-restrictions.html

Cursors are read only; you cannot use a cursor to update rows.

UPDATE WHERE CURRENT OF and DELETE WHERE CURRENT OF are not implemented, because updatable cursors are not supported.

Так что я думаю, вы не можете сделать это таким образом, и вы должны будете указать MySQL, как где пункт.

Смежные вопросы