如何在MySQL中将表名,列名和值传递到Storedprocedure中

时间:2018-08-09 05:26:49

标签: mysql stored-procedures

我正在尝试这个,但是会抛出错误

DELIMITER $$
CREATE  PROCEDURE usp_dynamicExc1 (Tablename varchar(100)
,Columnname  varchar(100),
Data varchar(100) )
BEGIN
SET @Tablename = Tablename;
SET @columnname = Columnname;
SET @value1 = Data;
SET @q= CONCAT('Insert into ',@tablename,' (',@columnname,') values (',@value1,')');
PREPARE stmt FROM @q;
EXECUTE stmt ;    DEALLOCATE PREPARE stmt;
END

我收到此错误

10:30:16    PREPARE stmt FROM @q    Error Code: 1064. 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 '' at line 1    0.000 sec

0 个答案:

没有答案