存储过程案例


DROP PROCEDURE IF EXISTS wms.chagecarpr2;
CREATE PROCEDURE wms.`chagecarpr2`()
BEGIN
declare i_rowon int default 0;
declare first_i_rowon int default 0;
declare so_id decimal(9,0);
declare so_no decimal(2,0);
declare carr_id decimal(9,0);
declare i_maxon INT;
declare first_i_maxon int;

declare first_cso_curon cursor for select ShipOrderID,SequenceNO,CarrierPrimary from twms_customershiporder where CSOStatus in(9953,9952) and CarrierPrimary is not null;
select count(*) into first_i_maxon from twms_customershiporder where CSOStatus in(9953,9952) and CarrierPrimary is not null;


open first_cso_curon;
getdataonfirst:loop
set first_i_rowon=first_i_rowon+1;
if first_i_rowon<first_i_maxon then
fetch first_cso_curon into so_id,so_no,carr_id;
update twms_customershiporder set SelectedCarrier=carr_id where ShipOrderID=so_id and SequenceNO=so_no;
ITERATE getdataonfirst;
end if;
leave getdataonfirst;
end loop getdataonfirst;
close first_cso_curon;


END;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个MySQL存储过程案例: ```sql DROP PROCEDURE IF EXISTS getUserInfo; CREATE PROCEDURE getUserInfo(in date_day datetime) BEGIN declare _userName varchar(12); -- 用户名 declare _chinese int; -- 语文 declare _math int; -- 数学 declare done int; -- 定义游标 DECLARE rs_cursor CURSOR FOR SELECT username, chinese, math from userInfo where datediff(createDate, date_day) = 0; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; -- 获取昨天的日期 if date_day is null then set date_day = date_add(now(), interval -1 day); end if; open rs_cursor; cursor_loop: loop FETCH rs_cursor into _userName, _chinese, _math; -- 取数据 if done = 1 then leave cursor_loop; end if; -- 更新表 update infoSum set total = _chinese + _math where UserName = _userName; end loop cursor_loop; close rs_cursor; END; ``` 这是一个存储过程名为getUserInfo的案例,参数为date_day,日期格式为2008-03-08。在该存储过程中,我们使用游标rs_cursor来查询userInfo表中与指定日期相差一天的记录。然后,我们通过一个循环来遍历游标获取的结果,并更新infoSum表中对应用户名的总分数。该存储过程使用了游标和循环结构来实现对数据的操作。<span class="em">1</span><span class="em">2</span> #### 引用[.reference_title] - *1* *2* [mysql存储过程案例](https://blog.csdn.net/wind_602/article/details/89883323)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值