我正在尝试使用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;