Mysql 存储过程应用

关闭订单存储过程sql

beginide

declare done int default 0;fetch

declare orderid varchar(22);spa

#声明查询订单的游标it

declare cur cursor for select orders.order_id from orders where orders.order_state =  'wait_pay';class

#异常处理sed

declare continue handler for sqlstate '02000' set done = 1;date

#打开游标定时任务

open cur;select

#遍历数据

fetch next from cur into orderid;

repeat

if not done then

#根据订单编号查询订单的下单时间

select orders.order_xiatime into @a from orders where order_id=orderid;

#根据订单下单时间获取1天后的时间(先用一天,存储过程正常使用后改成12小时间)

SELECT ADDDATE(@a, INTERVAL 24 Hour) into @b;

#判断会员在1天内是否未作任何处理

if @b<now() then

#自动更新订单的状态

update orders set order_state='trade_colsed',order_closetime = now() ,close_order_reason='订单关闭时间到,定时任务正常关闭' where order_id=orderid;

#如有多个操做能够在这里接着些

#回收库存(调用另外一个存储过程)

call recoveryOfInventory(orderid);

end if;

end if;

fetch next from cur into orderid;

until done end repeat;

close cur;

相关文章
相关标签/搜索