我认为问题在于查询 CONCAT (INSERT....) 中的字符示例 " 或 ' 我总是得到错误:
0 16:35:45 调用 InsertUser(990099,2,1,"Title1","Gosc","aaa","192.168.1.1",21426,23453245,1) 错误代码:1064。你有一个错误SQL 语法;检查与您的 MySQL 服务器版本相对应的手册,以在第 2 行的 '16:35:44, 1, 1)' 附近使用正确的语法
程序:
DELIMITER $$
DROP PROCEDURE IF EXISTS InsertUser $$
CREATE PROCEDURE `InsertUser`
(UserId int, ServiceId int(11), CommentsId int(11),
Title varchar(255), Nick varchar(20), content text,
Ip varchar(15), TableCrc int(5),Crc32 int(11) unsigned,
ArticleId int(11))
BEGIN
DECLARE tableName VARCHAR(65535);
set tableName = CONCAT('User',userId);
CALL CreateUsersTable(tableName);
set @a = CONCAT("INSERT INTO `", tableName ,"` (`ServiceId`,
`CommentsId`, `Title`, `Content`,`Ip`,
`TableCrc`, `Crc32`, `ArticleId`,`Date`,
`ViewStatus`, `CommentStatus`)
VALUES (",ServiceId,", ",CommentsId,", '",Title,"',
'",Content,"', '",Ip,"', ",TableCrc,",
",Crc32,", ",ArticleId,",
",now(),", 1, 1);");
PREPARE stmi FROM @a;
EXECUTE stmi;
DEALLOCATE PREPARE stmi;
END$$