开发者

Create MySQL event with a dynamic event name

开发者 https://www.devze.com 2023-03-11 12:19 出处:网络
I have to write a stored pro开发者_JAVA技巧cedure in which a event needs to be created. Since the stored procedure call depends on the action triggered, a different name needs to be given to the event

I have to write a stored pro开发者_JAVA技巧cedure in which a event needs to be created. Since the stored procedure call depends on the action triggered, a different name needs to be given to the event created.

CREATE EVENT variable
    ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 1 MINUTE
    DO
    Insert into dummy ('abc');

The variable name needs to be a dynamic variable, however mysql doesnt let me do that from a stored procedure. How can this be achieved?


It's not possible in MySQL, this:

PREPARE stmt_name FROM CONCAT(CREATE EVENT ",@variable
    ,"ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 1 MINUTE "
    ,"DO Insert into dummy (test) VALUES (?);"

SET @test_parm = "abc";

EXECUTE stmt_name USING @test_parm;
DEALLOCATE PREPARE stmt_name;

Doesn't work because you cannot do that in a prepared statement.

See: http://dev.mysql.com/doc/refman/5.5/en/sql-syntax-prepared-statements.html

0

精彩评论

暂无评论...
验证码 换一张
取 消