drop procedure if exists move_track_data;
delimiter //
create procedure move_track_data()
begin
declare i int default 0;
start transaction;
set i = 1;
case
when i = 1 then
select 'is 1';
when i = 2 then
select 'is 2';
else
select 'is 3';
end case;
commit;
end;
// call move_track_data();
delimiter ;
select * from score_driving_track where trackid in( select trackid from score_driving_track where trackid % 10 = 1); insert into score_driving_track_0 select * from score_driving_track where trackid in( select trackid from score_driving_track where trackid % 10 =0); ####################################################################################################3 set time_zone = '+8:00';
set GLOBAL event_scheduler = 1;
use test;
drop event if exists upload_to_sdmp;
DELIMITER //
create event upload_to_sdmp
on schedule every 1 week starts timestamp '2015-10-12 02:00:00'
do call move_score_driving_track_data(); drop procedure if exists move_score_driving_track_data;
delimiter //
create procedure move_score_driving_track_data()
begin
declare i int default 0;
declare t_error integer default 0;
declare continue handler for sqlexception set t_error = 1;
start transaction;
set i = 0;
while i < 10 do
set @sqlTrackids = concat('select group_concat(distinct trackid) into @trackids from score_driving_track where trackid % 10 = ', i);
select @sqlTrackids;
prepare sqlTrackidsNormal from @sqlTrackids;
execute sqlTrackidsNormal;
select @trackids; set @sqlInsert = concat('insert into score_driving_track_', i, ' select * from score_driving_track where find_in_set(trackid, ''', @trackids, ''')');
select @sqlInsert;
prepare sqlInsertNormal from @sqlInsert;
execute sqlInsertNormal; set @sqlDelete = concat('delete from score_driving_track', ' where find_in_set(trackid ,''', @trackids, ''')');
select @sqlDelete;
prepare sqlDeleteNormal from @sqlDelete;
#execute sqlDeleteNormal; set i = i + 1;
end while;
if t_error = 1 then
rollback;
else
commit;
end if;
end;
//
call move_score_driving_track_data();
SELECT @@global.sort_buffer_size; select * from score_driving_track where trackid >= 2270;
select * from score_driving_track_0;
select * from score_driving_track_1;
select * from score_driving_track_2;
select * from score_driving_track_3;
select * from score_driving_track_4;
select * from score_driving_track_5;
select * from score_driving_track_6;
select * from score_driving_track_7;
select * from score_driving_track_8;
select * from score_driving_track_9; delete from score_driving_track_0;
delete from score_driving_track_1;
delete from score_driving_track_2;
delete from score_driving_track_3;
delete from score_driving_track_4;
delete from score_driving_track_5;
delete from score_driving_track_6;
delete from score_driving_track_7;
delete from score_driving_track_8;
delete from score_driving_track_9; SET GLOBAL group_concat_max_len=1024000; show variables like "group_concat_max_len";
##################################################################################### call move_score_driving_track_data();
SELECT @@global.sort_buffer_size; SET GLOBAL group_concat_max_len=1024000; show variables like "group_concat_max_len"; select group_concat(distinct trackid) from score_driving_track where trackid % 10 = 0;
SELECT @@global.group_concat_max_len;
show warnings;
#[mysqld]
#explicit_defaults_for_timestamp=true
#group_concat_max_len=102400
select distinct trackid from score_driving_track where trackid % 10 = 0; select group_concat(distinct trackid) from score_driving_track where trackid % 10 = 0 and trackid < 50; delimiter ;
select concat('score_driving_track_', 1); select * from score_driving_track_0; delete from score_driving_track_0; ##############################################################################
set time_zone = '+8:00';
set GLOBAL event_scheduler = 1;
use test;
drop event if exists upload_to_sdmp;
DELIMITER //
create event upload_to_sdmp
on schedule every 1 second #starts timestamp '2014-07-30 10:00:00'
do
begin
insert into b values(3,'');
insert into b values(2,'');
end
//
DELIMITER ; select * from b; select group_concat(trackid) into @temp from score_driving_track where trackid < 100;
select @temp;
select * from score_driving_track where find_in_set(trackid, @temp);
select REPLACE(@temp,'''''''',''); select CHAR_LENGTH(@temp)-CHAR_LENGTH(REPLACE(@temp,'','')) + 1; select * from score_driving_track where trackid in (select group_concat(trackid) from score_driving_track where trackid < 50); select * from score_driving_track where find_in_set(trackid, (select group_concat(distinct trackid) from score_driving_track where trackid < 50)); select * from users;

MySQL 存储过程 定时任务的更多相关文章

  1. Mysql 存储过程+定时任务,完成分区自动维护

    建表: drop table if exists terminal_parameter; CREATE TABLE `terminal_parameter` ( `terminal_parameter ...

  2. 如何写mysql的定时任务

     什么是事件: 一组SQL集,用来执行定时任务,跟触发器很像,都是被动执行的,事件是因为时间到了触发执行,而触发器是因为某件事件(增删改)触发执行: 查看是否开启: show variables li ...

  3. Mysql编写定时任务事件

    原文:Mysql编写定时任务事件 场景: 例如:某系统,用户每天只能拥有一次的抽奖机会,抽过后当天就不可再抽,但是过了24:00点后用户就重新拥有一次抽奖机会.像这种需要数据库定时对某个字段进行更新操 ...

  4. MySQL job/定时任务/event 学习

    参考文章: https://blog.csdn.net/qq_21108311/article/details/82589850 https://blog.csdn.net/qq_27238185/a ...

  5. MySQL存储过程(转)

    一.MySQL 创建存储过程 "pr_add" 是个简单的 MySQL 存储过程,这个存储过程有两个 int 类型的输入参数 "a"."b" ...

  6. MySql存储过程

    MySQL 存储过程 ```sql CREATE PROCEDURE myprocedure (IN para01 INTEGER) BEGIN DECLARE var01 CHAR(10); IF ...

  7. mysql存储过程和存储函数

    mysql存储过程和存储函数 存数函数代码示例: DROP PROCEDURE IF EXISTS calc_ci_day_suc_rate; delimiter // CREATE FUNCTION ...

  8. mysql存储过程编写-入门案例-遁地龙卷风

    (-1)写在前面 这篇文章只是简要的叙述了mysql存储过程编写的基本概念. 我使用的mysql版本是5.7.9-log. 参照<<深入浅出MySQL>>. (0) delim ...

  9. MySQL存储过程动态SQL语句的生成

    用Mysql存储过程来完成动态SQL语句,使用存储过程有很好的执行效率: 现在有要求如下:根据输入的年份.国家.节假日类型查询一个节假日,我们可以使用一般的SQL语句嵌入到Java代码中,但是执行效率 ...

随机推荐

  1. Sublime text 3安装svn插件

    这几天在研究sublime text 3的使用,感觉还不错,现在想让他能够支持svn,所以就写一下怎么安装svn插件吧~ 首先先说一下这个官方的插件网站 点我进入~ 进入之后,最上边的第一个就是点击安 ...

  2. 在Mac上安装IntelliJ IDEA

    这篇文章旨在介绍如何在Mac系统上安装IntelliJ IDEA,至于IntelliJ IDEA的介绍和使用方法,大家另行查阅,本篇的文章不再详细阐述. 简短解说,IntelliJ IDEA是可以用来 ...

  3. C#完美实现斐波那契数列

    /// <summary>         /// Use recursive method to implement Fibonacci         /// </summary ...

  4. 学习springMVC框架配置遇到的问题-数据写入不进数据库时的处理办法

    配置完了,运行,数据写入不到数据库中,就应该想UserAction 中的handleRequest()方法有没有进去,然后就设置断点.如果发现程序没有进去,就再想办法进去.

  5. css2选择器

    CSS1&2元素选择器 选择符  类型  版本  简介 * 通配选择符 CSS2 所有元素对象. E 类型(HTML)选择符 CSS1 以文档语言对象类型作为选择符. E#myid id选择符 ...

  6. Ubuntu遇到Please ensure that adb is correctly located at '...adb.exe' and can be executed 问题解决方法

    上次我们在SDK更新的到最新的Android L版本之后,我发现我的ADT和android指定的版本不对应,我的ADT是22版本的,android L需要23版本以上的,版本不对应的话就无法加载这个S ...

  7. python dict

    ###字典的基本结构 info = { "k1" : "v1", "k2" : "v2" } ###字典的valus可以 ...

  8. php安装gearman扩展实现异步分步式任务

    参考: 1.小喵爱你的博客 2.PHP Manual 依赖 1.gcc44 2.boost >=1.39 3.libevent 4.php5.3+ 5.update ld.so.conf 安装依 ...

  9. c# 验证码类

    using System; using System.Drawing; using System.Drawing.Drawing2D; using System.Drawing.Imaging; us ...

  10. ArcGIS Engine代码共享-工作空间(workspace)对象操作

    代码: public class WorkspaceHelper { public static string GISConnectionString; public static IWorkspac ...