DELIMITER $$
USE `RTList`$$
DROP PROCEDURE IF EXISTS `INSERT_INTO_MT_Tables`$$
CREATE DEFINER=`root`@`localhost` PROCEDURE `INSERT_INTO_MT_Tables`(
IN mtTableName VARCHAR(10)
, IN mTableName VARCHAR(15)
, IN mtField VARCHAR(15)
, IN mtItemID VARCHAR(15)
, IN mtItemName VARCHAR(15)
, IN AdminID INT)
BEGIN
DECLARE @SQLString VARCHAR(200);
SET @SQLString =
'INSERT INTO ' + mtTableName +
'(' + mtItemID + ', ' + mtField + ', User_Created, Date_Created, User_Modified, Date_Modified)'
+ ' SELECT ' + mtItemID + ' , ' + mtField + ', AdminID, NOW(), AdminID, NOW()
FROM ' + mTableName + '
WHERE ' + mtField + ' = ''' + mtItemName + ''' LIMIT 1;';
PREPARE test FROM @SQLString;
EXECUTE test;
END$$
DELIMITER ;
CALL INSERT_INTO_MT_Tables('MT_Phone', 'M_Phone', 'Phone_Number', 'PhoneID', '12345678', 1);
这是我更改后的错误消息(结束后执行cmd):
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 'EXECUTE test;
DELIMITER' at line 2
这是我更改后的错误消息(在结束前执行 cmd):
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 '@SQLString VARCHAR(200);
SET @SQLString =
'INSERT INTO ' + mtTableName +
'(' + ' at line 9
你好呀,
请参阅我上面的编码。我对存储过程知之甚少。但在发布这个问题之前,我试图环顾四周。似乎 cmd 很简单,但仍然没有运气我可以运行这个 cmd。
你能告诉我我在哪里写错了,所以这不起作用吗?
非常感谢您对这个基本问题的了解。
谢谢。