MySql立即创建功能解决方案

时间:2015-03-23 06:07:25

标签: mysql stored-procedures

create function COMP_STMT(activeSTMT varchar(200),activeSQL varchar(200)) RETURNS INT
    BEGIN
        PREPARE activeSTMT from activeSQL;
        EXECUTE activeSTMT;
        DEALLOCATE PREPARE activeSTMT;
        return 1;
    END;

错误:

ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '@activeSTMT from @activeSQL' at line 3

我该如何解决?

1 个答案:

答案 0 :(得分:0)

您需要使用字符串文字或包含该语句文本的用户变量来使用Mysql中的PREPARE / EXECUTE语句。

BEGIN
 set @actSQL= activeSQL;
 PREPARE stmt FROM @actSQL;
 EXECUTE stmt;
 DEALLOCATE PREPARE stmt;
END