2012-08-14 60 views
0

我觉得proble是在查询CONCAT(INSERT ....)字符例如“或”我总是得到错误:不正确的INSERT现在()

0 16:35:45 call InsertUser(990099,2,1,"Title1","Gosc","aaa","192.168.1.1",21426,23453245,1) 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 '16:35:44, 1, 1)' at line 2

到程序:

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$$ 
+0

你试图把周围的现在报价()语句? ''“,now(),”',1,1);“);' – Steve 2012-08-14 14:46:59

+0

是的,我是真的,但它不起作用 – Przemek 2012-08-14 15:07:46

+0

它现在确定问题是与参数在输入 – Przemek 2012-08-14 15:15:49

回答

0

有一个在()

YYYY-MM-DD HH:MM:SS 
     ^

在你的SQL语句现在返回的字符串值的嵌入式领域,需要处理作为一个字符串,这意味着它需要用单引号括起来。作为一个独立的问题,你不需要分号作为你的SQL文本的一部分:

改变这一点:

", ",now(),", 1, 1);"); 
       ^

这样:

", '",now(),"', 1, 1)"); 
^  ^
+0

谢谢你的帮助!:) – Przemek 2012-08-16 07:29:56