3>存储过程维护项目数据

30 篇文章 1 订阅
DROP PROCEDURE IF EXISTS repalceSizeService;
CREATE PROCEDURE repalceSizeService()
BEGIN
declare _size_level int(10); 
declare _price int(10); 
declare _code_business VARCHAR(30); 
declare done int;

-- 定义游标
DECLARE rs_cursor CURSOR FOR 
select item_code_business,size_level,price from imc_channelbusiness_service_item_size_price where type_code=@old;

DECLARE CONTINUE HANDLER FOR NOT FOUND SET done=1;

open rs_cursor; 
cursor_loop:loop
   FETCH rs_cursor into _code_business,_size_level,_price; -- 取数据
   
   if done=1 then
    leave cursor_loop;
   end if;
   	
-- 更新表
   update imc_channelbusiness_service_item_size_price set price=_price where size_level =_size_level and item_code_business=_code_business and type_code=@new;

end loop cursor_loop;
close rs_cursor;

END;

 set @old = 'ZETY5317788667869077';
 set @new = 'ZETY5317788849451086';
 call repalceSizeService();

带参数

DROP PROCEDURE IF EXISTS copyPhoneJson;
CREATE PROCEDURE copyPhoneJson(in _month VARCHAR(30), in _vendor_code VARCHAR(30))
BEGIN
declare _phone VARCHAR(40); 
declare _price_json VARCHAR(3000); 
declare done int;
 
-- 定义游标
DECLARE rs_cursor CURSOR FOR 
select phone,price_json from bms_cost_phones where month='2019-08' and call_vendor=_vendor_code and price_json is not null;
 
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done=1;
 
open rs_cursor; 
cursor_loop:loop
   FETCH rs_cursor into _phone,_price_json; -- 取数据
   
   if done=1 then
    leave cursor_loop;
   end if;
   	
-- 更新表
   update bms_cost_phones set price_json=_price_json where month=_month and call_vendor=_vendor_code and phone=_phone;
 
end loop cursor_loop;
close rs_cursor;
 
END;
DELIMITER $$

DROP PROCEDURE IF EXISTS updateStockMoves $$

CREATE PROCEDURE updateStockMoves()
-- 
-- 实例
-- MYSQL存储过程名为:updateStockMoves
--
BEGIN
declare _stock_sup_id int(10);
declare _enter_time datetime ; 
declare _qty double ;
declare _out_time datetime ;
declare _stock_mv_id int(10);    
declare done int;

-- 定义游标
DECLARE rs_cursor CURSOR FOR 
SELECT a.stock_sup_id,a.enter_time,a.qty,b.out_time 
from pre_doc_item a 
left join prepare_doc b on a.pre_doc_id=b.pre_doc_id order by a.pre_item_id asc;

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 _stock_sup_id, _enter_time, _qty, _out_time; -- 取数据

   if done=1 then
    leave cursor_loop;
   end if;
     
	 select min(stock_mv_id) into _stock_mv_id from stock_moves where mv_time is null and job_id is null 
	 and stock_sup_id=_stock_sup_id 
	 and in_time=_enter_time and abs(qty)= _qty;

	 insert into temp_updateStockMoves_select(stock_sup_id,enter_time,qty,out_time,stock_mv_id) SELECT _stock_sup_id,_enter_time,_qty,_out_time,_stock_mv_id; 
	
-- 更新表
   update stock_moves set mv_time=_out_time where mv_time is null and job_id is null 
	 and stock_sup_id=_stock_sup_id 
	 and in_time=_enter_time and abs(qty)= _qty and stock_mv_id=_stock_mv_id;
   update stock_moves set mv_time=_out_time where mv_time is null and job_id is null 
	 and stock_sup_id=_stock_sup_id 
	 and in_time=_enter_time and abs(qty)= _qty and stock_mv_id=(_stock_mv_id+1);

insert into temp_updateStockMoves_update(stock_mv_id,mv_time) select _stock_mv_id,_out_time;

insert into temp_updateStockMoves_update(stock_mv_id,mv_time) select _stock_mv_id+1,_out_time;
	
end loop cursor_loop;
close rs_cursor;

END$$

DELIMITER ;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值