0

任何人都可以帮我找到以下 MS SQL 语法的 mysql corespondent 吗?

CREATE PROCEDURE testsp @COLUMN_NAME VARCHAR(20), @COLUMN_VALUE VARCHAR(20)
AS

DECLARE @SQL VARCHAR(40)  
SET @SQL = 'UPDATE TableX set ''+@COLUMN_NAME+ ''=''+@COLUMN_VALUE+'' '
PRINT (@SQL)
EXEC (@SQL)

是否可以将此代码翻译成Mysql?

谢谢!

4

1 回答 1

2
CREATE PROCEDURE testsp (COLUMN_NAME VARCHAR(20), COLUMN_VALUE VARCHAR(20))
BEGIN
    SET @SQL_COMMAND = CONCAT('UPDATE TableX SET ', COLUMN_NAME, ' = ?');
    SELECT @SQL_COMMAND; /* prints the command */
    PREPARE SQL_STMT FROM @SQL_COMMAND;
    EXECUTE SQL_STMT USING COLUMN_VALUE;
    DEALLOCATE SQL_STMT;
END
于 2012-06-05T20:01:49.280 回答