Mysql基础第二十七天,使用游标
原创
©著作权归作者所有:来自51CTO博客作者2019ab的原创作品,请联系作者获取转载授权,否则将追究法律责任
游标
使用游标
call pressorders(); // 使用游标
创建游标
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; // 删除游标