mysql简单存储过程范例

来源:互联网 发布:麦当劳上海数据 编辑:程序博客网 时间:2024/06/05 20:58

范例:

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
原创粉丝点击