mysql简单存储过程范例

范例:

BEGIN
  -- 定义参数 
	declare carId int(10);
	declare v_count int;
	declare done int default 1;
  -- 一个游标(cursor)可以被看作指向结果集(a set of rows)中一行的指针(pointer)
	declare logisticCarInfoCursor cursor for select id from logistic_car_info;
	select count(1) into v_count from logistic_car_info;
  -- 开始提交
	start transaction;
  -- 打开结果集
	open logisticCarInfoCursor;
  -- 循环结果中的数量
	while done <  v_count +1 do
  -- 游标是好几个值,并且可以有N条记录,fetch游标into到变量里
		fetch logisticCarInfoCursor into carId;	  
  -- 最终将物流信息表中的数据更新为已支付的状态							
									update logistic_car_execute_report  lcer ,trading_record  tr 
                  set tr.pay_state=1, account_state=1 where lcer.car_id=carId and tr.trad_code=lcer.batch_id and lcer.pay_flag='1' and state='4' and tr.pay_state=0;
--执行一次数据加一
	set done= done +1;
--结束循环
	end while;
--关闭游标
	close logisticCarInfoCursor;、
--提交
	COMMIT;
END



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值