MySQL trigger/procedure execution delay

前端 未结 2 2118
忘掉有多难
忘掉有多难 2020-12-17 00:01

Is there a decent way to delay execution of mysql trigger?

WHILE @condition = 0
  sleep for awhile

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


        
相关标签:
2条回答
  • 2020-12-17 00:13

    Since MySQL 5.0.12, you can do this:

    SELECT SLEEP(<seconds>);
    

    The seconds parameter can be in a fraction of a second like .5.

    0 讨论(0)
  • 2020-12-17 00:20
    DO SLEEP(<seconds>);
    

    is better. There is no reason to just run SELECT statements inside triggers without needing the result set. 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. 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:

    BEGIN
        DO SLEEP(<seconds>);
        UPDATE ...;
    END
    
    0 讨论(0)
提交回复
热议问题