mysql中event例子

 mysql中event例子

-- Create event ev_test_006
delimiter $$
Create event ev_test_006 on schedule every 35 MINUTE 
DO
Begin
    declare v_di_game_id int;
	declare v_di_database varchar(50);
	declare m_stop_flag int default 0;
	declare cursor_game cursor for  select di_game_id,di_database from t910_database_info;
	declare continue handler for not found set m_stop_flag=1; 
	open cursor_game;
	    
	repeat fetch cursor_game into v_di_game_id,v_di_database;
	    if m_stop_flag=0 then
	        
	        -- t_user_remain
	        set @v_sql=concat("delete from t006_today_data where td_game_id=",v_di_game_id);
	        prepare stmt from @v_sql;
	        EXECUTE stmt;
	        deallocate prepare stmt;
	        
	        set @v_sql=concat("insert into t006_today_data(td_game_id,td_server_id,td_platform_id,td_channel_id,td_calc_date,td_user_reg_count,td_user_reg_count_total,td_user_pay_new_count,td_amount,td_amount_total,td_update_time,td_create_time) select ",v_di_game_id,",td_server_id,td_platform_id,td_channel_id,td_calc_date,td_user_reg_count,td_user_reg_count_total,td_user_pay_new_count,td_amount,td_amount_total,td_update_time,date_format(now(),'%Y-%m-%d %H:%i:%s') from ",v_di_database,".t006_today_data where td_calc_date=date_format(now(),'%Y-%m-%d')");
	        prepare stmt from @v_sql;
	        EXECUTE stmt;
	        deallocate prepare stmt;
	        
	    end if;
	until m_stop_flag=1 end repeat;
	close cursor_game;

END $$
delimiter ;

猜你喜欢

转载自stephen830.iteye.com/blog/2144799