Mysql下写一个存储过程并将更新的数据插入到日志表里。运行时报错了,报的sql语句错了,求大神解决
begindeclaredoneintdefault0;declareorder_idint;declaredomainvarchar(30);declareshop_i...
begin
declare done int default 0;
declare order_id int;
declare domain varchar(30);
declare shop_id int ;
declare order_type varchar(20);
declare opera_explain varchar(100);
declare record_time = now() varchar(20);
declare record_user varchar(20);
declare cur cursor for select fo.shop_id, fo.order_id fo.domain fo.order_type fo.opera_explain fo.record_user from shop_food_order fo where fo.state='wait_confirm' and (now()-fo.order_time)>(24*3600);
DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1;
open cur;
fetch next from cur into order_id;
repeat;
if not done then
update shop_food_orderitem foi set foi.state='trade_closed' ,foi.closed_time=now() where foi.order_id = fo.order_id;
update shop_food_order set state='trade_closed', order_time=now(),closed_time=now() where order_id = order_id;
insert into log_order(shop_id ,domain ,order_id ,order_type ,opera_explain ,record_time ,record_user ) values(?,?,?,?,?,?,?);
end if;
fetch next from cur into order_id;
UNTIL done END REPEAT;
close cur;
end; 展开
declare done int default 0;
declare order_id int;
declare domain varchar(30);
declare shop_id int ;
declare order_type varchar(20);
declare opera_explain varchar(100);
declare record_time = now() varchar(20);
declare record_user varchar(20);
declare cur cursor for select fo.shop_id, fo.order_id fo.domain fo.order_type fo.opera_explain fo.record_user from shop_food_order fo where fo.state='wait_confirm' and (now()-fo.order_time)>(24*3600);
DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1;
open cur;
fetch next from cur into order_id;
repeat;
if not done then
update shop_food_orderitem foi set foi.state='trade_closed' ,foi.closed_time=now() where foi.order_id = fo.order_id;
update shop_food_order set state='trade_closed', order_time=now(),closed_time=now() where order_id = order_id;
insert into log_order(shop_id ,domain ,order_id ,order_type ,opera_explain ,record_time ,record_user ) values(?,?,?,?,?,?,?);
end if;
fetch next from cur into order_id;
UNTIL done END REPEAT;
close cur;
end; 展开
3个回答
展开全部
update shop_food_orderitem foi set foi.state='trade_closed' ,foi.closed_time=now() where foi.order_id = fo.order_id;
fo是什么表的别名?
例子:
update A set A.field=B.field1 from B where A.id=B.id
update shop_food_order set state='trade_closed', order_time=now(),closed_time=now() where order_id = order_id;
你这个where条件永远是真的
insert into log_order(shop_id ,domain ,order_id ,order_type ,opera_explain ,record_time ,record_user ) values(?,?,?,?,?,?,?);
?是什么值?
fo是什么表的别名?
例子:
update A set A.field=B.field1 from B where A.id=B.id
update shop_food_order set state='trade_closed', order_time=now(),closed_time=now() where order_id = order_id;
你这个where条件永远是真的
insert into log_order(shop_id ,domain ,order_id ,order_type ,opera_explain ,record_time ,record_user ) values(?,?,?,?,?,?,?);
?是什么值?
今至电子科技有限公司
2024-08-23 广告
2024-08-23 广告
数据库备份是确保数据安全与业务连续性的关键环节。我们上海今至电子科技有限公司高度重视数据保护,定期执行全面的数据库备份策略。这包括使用先进工具和技术,对关键业务数据进行自动化备份,并存储在安全可靠的外部存储介质或云端。通过定期验证备份的完整...
点击进入详情页
本回答由今至电子科技有限公司提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询