首页 > 代码库 > mysql 存储过程中使用事物+事件定时执行存储过程

mysql 存储过程中使用事物+事件定时执行存储过程

(1)存储过程

DROP PROCEDURE IF EXISTS proc_test;
CREATE  PROCEDURE proc_test()
BEGIN
  DECLARE t_error INTEGER DEFAULT 0;    
  DECLARE CONTINUE HANDLER FOR SQLEXCEPTION SET t_error=1; 
  START TRANSACTION; 

    insert into score_record_bak(openid, nickname, city_id, city_name, grid_number, score_type, 
   channel_manager_score, channel_manager_remark, railcom_support_score, railcom_support_remark, 
   manager_support_score, manager_support_remark, insert_time, weixin_accountid)
  select openid, nickname, city_id, city_name, grid_number, score_type, 
   channel_manager_score, channel_manager_remark, railcom_support_score, railcom_support_remark, 
   manager_support_score, manager_support_remark, insert_time, weixin_accountid
  from score_record;
  DELETE from dezhou_score_record;

  IF t_error = 1 THEN    
      ROLLBACK;    
  ELSE    
      COMMIT;    
  END IF;  
END;

(2)事件

定时执行存储过程
CREATE EVENT if not exists e_dezhou_score_record
ON SCHEDULE EVERY 1 MONTH STARTS ‘2017-05-01 00:00:00‘
ON COMPLETION NOT PRESERVE ENABLE
DO CALL proc_test();

mysql 存储过程中使用事物+事件定时执行存储过程