mysql 游标

来源:百度知道 编辑:UC知道 时间:2024/06/17 15:06:55
请问是否可以在循环中定义游标:
如下,报错。(所有的变量都已定义)
while i<=17 do
set i=i+1;
select combine1 into comb1 from temp6 where id=i;
select combine2 into comb2 from temp6 where id=i;
select total into total1 from temp6 where id=i;
select count(id) into recordcount from temp5 where combine1=comb1;
declare cur1 CURSOR for select id from temp5 where combine1=comb1;
declare CONTINUE HANDLER FOR not found set identity1=0;
open cur1;

while n<= recordcount do
set total5 = total3;
fetch cur1 into identity1;
select total into total3 from temp5 where id=identity1;
select combine2 into comb3 from temp5 where id=identity1;

select combine2 into tmpName from temp6 where combine1= comb3;

if tmpName is not null then
select combine2 into comb4 from temp6 where combine1= comb3;

根本就不可能通过。你在一个存储过程中写两 declare continue handler for not found set done = 1;看能通过吗。别费劲了。

set total5 = total3;
fetch cur1 into identity1;
select total into total3 from temp5 where id=identity1;
select combine2 into comb3 from temp5 where id=identity1
在原有程序中进行专有变革

close cur1; --倒数第二行
在加一句 deallocate cur1;
你试试吧