CREATE PROCEDURE curdemo()
BEGIN
DECLARE done INT DEFAULT 0;
declare pid varchar(40);
DECLARE cur1 CURSOR FOR select a.id from oy_trade_order a
join oy_trade_order_contract_relation b on a.id=b.order_id
join oy_trade_contract c on b.contract_id=c.id
join oy_trade_contract_materiel d on c.id=d.contract_id
where a.deleted_flag=0 and b.deleted_flag=0 and c.deleted_flag=0
and d.deleted_flag=0 and c.contract_type=0
-- and a.falish=0
and a.state=3;
DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1;
open cur1;
REPEAT
fetch cur1 into pid;
if NOT done THEN
update oy_trade_order set falish=0 where id=pid;
end if;
until done end repeat;
close cur1;
end
来源:CSDN
作者:car-java
链接:https://blog.csdn.net/fandongbao/article/details/103721831