create procedure c(in price1 float, in price2 float,out count int)
begin
declare sum int ;
declare temp_price float;
declare cur cursor for select price from food;
declare exit handler for not found close cur;
set @sum = 0;
set @temp_price = 0;
OPEN cur;
repeat
fetch cur into temp_price;
if temp_price > price1 and temp_price < price2
then set @sum = @sum +1;
end if;
until 0 end repeat;
CLOSE cur;
set count = 50;
/*为什么这里无论写这个还是写成 set count = sum;在调用时 count 总是空呢?*/
endcall c(2,20,@count)select @count
总是返回NULL
begin
declare sum int ;
declare temp_price float;
declare cur cursor for select price from food;
declare exit handler for not found close cur;
set @sum = 0;
set @temp_price = 0;
OPEN cur;
repeat
fetch cur into temp_price;
if temp_price > price1 and temp_price < price2
then set @sum = @sum +1;
end if;
until 0 end repeat;
CLOSE cur;
set count = 50;
/*为什么这里无论写这个还是写成 set count = sum;在调用时 count 总是空呢?*/
endcall c(2,20,@count)select @count
总是返回NULL
fetch cur into temp_price;
select temp_price
...
create procedure c(in price1 float, in price2 float,out count int)
begin
declare sum int ;
declare temp_price float;
set count = 50;
end看是否正常,估计是你的工具的问题。
用这个吧原来那个handler的声明代替
然后until 那里换成until @a=1即可
因为你那个handler处理的是游标没有关闭的情况,而问题是出在游标循环取数据最终没有数据可取的情况
囧死,点错了
因为你那个handler处理的是游标没有关闭的情况,而问题是出在游标循环取数据最终没有数据可取的情况