存储函数或触发器中不允许使用动态SQL

时间:2016-09-22 18:20:30

标签: mysql stored-procedures dynamic-sql

我正在尝试使用mysql创建动态函数,并获得错误。我该怎么解决呢。

CREATE function updateTable(user_name Varchar(50), item_name Varchar(50), item_val Varchar(50)) RETURNS int
    BEGIN
    SET @item_val = item_val;
    SET @item_name = item_name;
    SET @user_name = user_name;
    IF @item_val = '' THEN
    SET @myCommand = concat('UPDATE table SET @item_name = null , row_modified =  CURRENT_TIMESTAMP WHERE user_id = @user_name;');
    PREPARE stmt FROM @myCommand;
    EXECUTE stmt;
    DEALLOCATE PREPARE stmt;
    ELSE
    SET @myCommand = concat('UPDATE table SET @item_name = @item_val , row_modified =  CURRENT_TIMESTAMP WHERE user_id = @user_name;');
    PREPARE stmt1 FROM @myCommand;
    EXECUTE stmt1;
    DEALLOCATE PREPARE stmt1;
    END IF;
    RETURN 1;

    END;

0 个答案:

没有答案