简体   繁体   English

MySQL触发器/过程执行延迟

[英]MySQL trigger/procedure execution delay

Is there a decent way to delay execution of mysql trigger? 有没有一种体面的方法来延迟mysql触发器的执行?

WHILE @condition = 0
  sleep for awhile

insert into some_table values(NEW.value1, NEW.value2);

Since MySQL 5.0.12, you can do this: 从MySQL 5.0.12开始,您可以执行以下操作:

SELECT SLEEP(<seconds>);

The seconds parameter can be in a fraction of a second like .5. 秒参数可以在几分之一秒之内,例如.5。

DO SLEEP(<seconds>);

is better. 更好。 There is no reason to just run SELECT statements inside triggers without needing the result set. 没有理由只在触发器内运行SELECT语句而不需要结果集。 If you really want to do this you need to do it like here: 如果您确实想这样做,则需要像下面这样:

SET @nothing = (SELECT SLEEP(<seconds>));

But I recommend to use DO . 但是我建议使用DO And don't forget that a trigger is just a single statement per default. 并且不要忘记,触发器只是默认情况下的一条语句。 If you have more then 1 statement in your trigger you need to use BEGIN / END : 如果触发器中包含1条以上的语句,则需要使用BEGIN / END

BEGIN
    DO SLEEP(<seconds>);
    UPDATE ...;
END

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM