MySQL进阶技巧:深入理解游标
最编程
2024-08-05 08:00:36
...
delimiter //
create procedure cursor_loop()
begin
declare fruit_price decimal(8,2);
declare fruit_name char(255);
declare done int default false;
DECLARE cursor_fruit CURSOR FOR SELECT f_name, f_price FROM fruits ;
declare continue handler for not found set done=true;
open cursor_fruit ;
my_loop:LOOP
FETCH cursor_fruit INTO fruit_name, fruit_price ;
if done then
leave my_loop;
end if;
select fruit_name, fruit_price ;
end loop;
close cursor_fruit ;
end;
//
delimiter ;