首页 > 代码库 > mysql 使用存储过程,事件等的一些小笔记 [Mark]
mysql 使用存储过程,事件等的一些小笔记 [Mark]
------------------------------------------------------------------------------------------------
[创建存储过程,使用变量,随机数字]
DELIMITER $$
DROP PROCEDURE IF EXISTS `week_luck_call` $$
CREATE PROCEDURE week_luck_call()
begin
DECLARE var_rankluck INT DEFAULT 99999; -- 必须放在第一行
delete from rankluck;
set var_rankluck = ROUND(ROUND(RAND(),5)*100000);
insert into rankluck (`guid`, `luck`) select `guid`, var_rankluck from ranklist order by value desc limit 100;
end $$
DELIMITER ;
------------------------------------------------------------------------------------------------
[创建mysql事件,事件触发时间、周期等]
delimiter $$
create procedure week_luck_call()
begin
delete from rankluck;
insert into rankluck (`guid`, `luck`) select `guid`, ROUND(ROUND(RAND(),5)*100000) from ranklist order by value desc limit 100;
end $$
delimiter ;
drop procedure week_luck_call;
create event week_luck on schedule every 1 week starts ‘2014-12-17 08:00:00‘ on completion preserve do call week_luck_call();
drop event week_luck;
mysql 使用存储过程,事件等的一些小笔记 [Mark]