mysql游标更新数据

徘徊边缘 提交于 2019-12-27 00:39:04

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

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!