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

简介:
Java代码   收藏代码
  1. DROP PROCEDURE IF EXISTS updateCustomerCharge;  
  2. CREATE PROCEDURE updateCustomerCharge()  
  3. --   
  4. -- 实例  更新用户信息是否充值  
  5. -- MYSQL存储过程名为:updateCustomerCharge   
  6. --  
  7. BEGIN  
  8. declare _customer_id int(10);   
  9. declare done int;  
  10.   
  11. -- 定义游标  
  12. DECLARE rs_cursor CURSOR FOR   
  13. select customer_id from virtualcurrency_logs where action='recharge_add' group by customer_id;  
  14.   
  15. DECLARE CONTINUE HANDLER FOR NOT FOUND SET done=1;  
  16.   
  17. open rs_cursor;   
  18. cursor_loop:loop  
  19.    FETCH rs_cursor into _customer_id; -- 取数据  
  20.      
  21.    if done=1 then  
  22.     leave cursor_loop;  
  23.    end if;  
  24.       
  25. -- 更新表  
  26.    update customer_entity set is_charge=1 where entity_id=_customer_id ;  
  27.   
  28. end loop cursor_loop;  
  29. close rs_cursor;  
  30.   
  31. END;  

select min(stock_mv_id) into _stock_mv_id

Java代码   收藏代码
  1. DELIMITER $$  
  2.   
  3. DROP PROCEDURE IF EXISTS updateStockMoves $$  
  4.   
  5. CREATE PROCEDURE updateStockMoves()  
  6. --   
  7. -- 实例  
  8. -- MYSQL存储过程名为:updateStockMoves  
  9. --  
  10. BEGIN  
  11. declare _stock_sup_id int(10);  
  12. declare _enter_time datetime ;   
  13. declare _qty double ;  
  14. declare _out_time datetime ;  
  15. declare _stock_mv_id int(10);      
  16. declare done int;  
  17.   
  18. -- 定义游标  
  19. DECLARE rs_cursor CURSOR FOR   
  20. SELECT a.stock_sup_id,a.enter_time,a.qty,b.out_time   
  21. from pre_doc_item a   
  22. left join prepare_doc b on a.pre_doc_id=b.pre_doc_id order by a.pre_item_id asc;  
  23.   
  24. DECLARE CONTINUE HANDLER FOR NOT FOUND SET done=1;  
  25.   
  26. -- 获取昨天的日期  
  27. --if date_day is null then  
  28. --   set date_day = date_add(now(),interval -1 day);  
  29. --end if;  
  30.   
  31. open rs_cursor;   
  32. cursor_loop:loop  
  33.    FETCH rs_cursor into _stock_sup_id, _enter_time, _qty, _out_time; -- 取数据  
  34.   
  35.    if done=1 then  
  36.     leave cursor_loop;  
  37.    end if;  
  38.        
  39.      select min(stock_mv_id) into _stock_mv_id from stock_moves where mv_time is null and job_id is null   
  40.      and stock_sup_id=_stock_sup_id   
  41.      and in_time=_enter_time and abs(qty)= _qty;  
  42.   
  43.      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;   
  44.       
  45. -- 更新表  
  46.    update stock_moves set mv_time=_out_time where mv_time is null and job_id is null   
  47.      and stock_sup_id=_stock_sup_id   
  48.      and in_time=_enter_time and abs(qty)= _qty and stock_mv_id=_stock_mv_id;  
  49.    update stock_moves set mv_time=_out_time where mv_time is null and job_id is null   
  50.      and stock_sup_id=_stock_sup_id   
  51.      and in_time=_enter_time and abs(qty)= _qty and stock_mv_id=(_stock_mv_id+1);  
  52.   
  53. insert into temp_updateStockMoves_update(stock_mv_id,mv_time) select _stock_mv_id,_out_time;  
  54.   
  55. insert into temp_updateStockMoves_update(stock_mv_id,mv_time) select _stock_mv_id+1,_out_time;  
  56.       
  57. end loop cursor_loop;  
  58. close rs_cursor;  
  59.   
  60. END$$  
  61.   
  62. DELIMITER ;  
相关文章
|
9月前
|
存储
SqlServer存储过程应用二:分页查询数据并动态拼接where条件 (下)
SqlServer存储过程应用二:分页查询数据并动态拼接where条件 (下)
|
9月前
|
存储 SQL 数据库连接
SqlServer存储过程应用二:分页查询数据并动态拼接where条件 (上)
SqlServer存储过程应用二:分页查询数据并动态拼接where条件
|
存储 关系型数据库 MySQL
【MySQL】使用存储过程+IF控制语句批量添加数据
【MySQL】使用存储过程+IF控制语句批量添加数据
230 0
【MySQL】使用存储过程+IF控制语句批量添加数据
使用存储过程批量更新单表中的数据
使用存储过程批量更新单表中的数据
|
存储 关系型数据库 MySQL
mysql数据库编写存储过程实现批量插入1000万条数据
mysql数据库编写存储过程实现批量插入1000万条数据
631 0
mysql数据库编写存储过程实现批量插入1000万条数据
|
存储 SQL 关系型数据库
PolarDB-X 1.0-常见问题-数据兼容问题-PolarDB-X支持MySQL的存储过程、跨库外键和级联删除等高级特性吗?
目前PolarDB-X不支持存储过程、跨库外键和级联删除。如果需要自定义函数,请尝试通过组合MySQL标准函数解决。详情请参见SQL使用限制。
480 0