mysql 事件 函数_MYSQL创建事件函数

create event event_delnull on schedule every 1 minute starts '2010-12-28 14:55:00' ends'2010-12-28 15:00:00' do insert into master values(100,100,100,now());

CREATE EVENT e_totals

ON SCHEDULE AT '2006-02-10 23:59:00'

DO

INSERT INTO messages VALUES (null, '恭喜发财');

CREATE EVENT e_hourly

ON `temp`

EVERY 10 SECOND STARTS '2011-09-25 00:00:00' ENDS '2012-09-25 00:00:00'

DO

INSERT INTO `mytab` VALUES (null, '恭喜发财');

create event e on schedule every 1 second do insert into `temp.t` values (null, '恭喜发财');

create event myevent on schedule every 1 second do insert into test.t values (current_timestamp);

create event up_team_time on schedule at NOW() do

begin

declare num_min int(10) default 0;

while num_min<10 do

set num_min = num_min + 1;

insert into mytab.t values (null,'插入文字');

end while;

commit;

end;

create event up_team_time on schedule at NOW() do

insert into mytab.t values (null,'插入文字');

create event up_team_time on schedule at NOW() on completion preserve do insert into test.t values (NULL,'插入文字');

create event if not exists `up_team_time` on schedule every 1 day starts '2011-01-01 23:50:00' on completion preserve enable do call up_team_time();

create event if not exists `up_team_time` on schedule every 1 second starts '2011-01-01 12:00:00' on completion preserve disable do call up_team_time();

alter event if not exists `up_team_time` on schedule every 1 second starts '2011-01-01 12:00:00' on completion preserve disable do call up_team_time();

查看运行中的进程~ SHOW PROCESSLIST;

删除任务 DROP EVENT if not exists up_team_time; DROP EVENT up_team_time;

开启计划任务进程 set global event_scheduler = 1;

开启事件 ALTER EVENT up_team_time ENABLE;

修改时间 ALTER EVENT `up_team_time` ON SCHEDULE EVERY 1 DAY STARTS '2011-01-01 23:50:00';

停止事件 ALTER EVENT up_team_time DISABLE;

MYSQL终止设置符号 delimiter $$

修改MY.ini文件

开机自动打开进程 event_scheduler=1

create function `fun_team_time`()

returns int(10)

begin

insert into mytab.t values (null,'插入文字');

return 1;

end$$

CREATE FUNCTION `SHORTEN`(S VARCHAR(255), N INT)

RETURNS varchar(255)

BEGIN

IF ISNULL(S) THEN

RETURN '';

ELSEIF N<15 THEN

RETURN LEFT(S, N);

ELSE

IF CHAR_LENGTH(S) <=N THEN

RETURN S;

ELSE

RETURN CONCAT(LEFT(S, N-10), '...', RIGHT(S, 5));

END IF;

END IF;

END;

CREATE FUNCTION myFunction

(in_string VARCHAR(255),

in_find_str VARCHAR(20),

in_repl_str VARCHAR(20))

RETURNS VARCHAR(255)

BEGIN

DECLARE l_new_string VARCHAR(255);

DECLARE l_find_pos INT;

SET l_find_pos=INSTR(in_string,in_find_str);

IF (l_find_pos>0) THEN

SET l_new_string=INSERT(in_string,l_

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值