创建游标
create procedure processorders()
begin
declare ordernumbers cursor
for
select order_num from orders;
end;
打开游标
open ordernumbers;
关闭游标
close ordernumbers;
使用游标
从游标中检索单个行
create procedure processorders()
begin
declare ordernumbers cursor
for
select order_num from orders;
open ordernumbers;
fetch ordernumbers into o;
close ordernumbers;
end;
循环检索数据
create procedure processorders()
begin
declare done boolean default o;
declare 0 int;
declare ordernumbers cursor
for
select order_num from orders;
declare continue handler for sqlstate '02000' set done = 1;
open ordernumbers;
repeat
fetch ordernumbers into o;
until done end repeat;
close ordernumbers;
end;