游标

使用游标

call pressorders(); // 使用游标

Mysql基础第二十七天,使用游标_sql

创建游标
create procedure precessorders()
begin
declare done boolean default 0;
declare t decimala(10,2);
declare o int;
declare ordernumbers cursor for select order_num from orders;
declare continue bandler for sqlsate='0200' set done=1;
create table if not exists ordertotals(order_num int,total decimal(10,2)
open ordernumbers;
repeat
fetch ordernumbers into o;
call ordertotal(o,1,t)
insert into ordertotals values (o,t)
until done end repeat;
close ordernumbers;
select * from ordertotals;
end;
打开和关闭游标
open ordernumbers; //打开
repeat
fetch ordernumbers into o;
call ordertotal(o,1,t)
insert into ordertotals values (o,t)
until done end repeat;
close ordernumbers; //关闭
删除游标
deallocate ordernumbers; // 删除游标