2010-08-24 160 views
2
INSERT INTO `tims`.`pending_profile`(`id`, `nickname`, `location`, `role`, `yog`, `interests`, `favMoment`, `gainThisYr`, `futurePlans`, `bio`) 
VALUES ('1', '1', '1', '1', '', '1', '1', '1', '1', '1') 
ON DUPLICATE KEY UPDATE (nickname ='1', location= '1', role= '1',yog= '1',interests= '1',favMoment= '1',gainThisYr= '1',futurePlans= '1',bio= '1') 

什么是触发这个错误?SQL错误,我不明白

您的SQL语法错误; (昵称='1',位置='1',角色='1',yog ='1',兴趣='1',favMoment),查看与您的MySQL服务器版本对应的手册=在行“1”” 3

+0

右括号没有匹配的开括号 – randomThought 2010-08-24 19:43:06

+0

如果这些数字确实是数字,那么它们也不应该放在引号内。 – 2010-08-24 19:49:55

+0

感谢你们大家 下面是工作代码: INSERT INTO'tims'.'pending_profile'('id','nickname','location','role','yog','interests', ('1','1','1','1','','1','1','1','1','1','fav','gainThisYr','futurePlans','bio') VALERES '1','1') ON DUPLICATE KEY UPDATE nickname ='1',location ='1',role ='1',yog ='1',interest ='1',favMoment ='1',gainThisYr ='1',futurePlans ='1',bio ='1' – TechplexEngineer 2010-08-24 19:58:00

回答

4

认沽逗号字段之间的:

INSERT INTO tims.pending_profile 
    (id, nickname, location, role, yog, interests, favMoment, gainThisYr, futurePlans, bio) 
VALUES 
    ('', '1', '1', '1', '', '1', '1', '1', '1', '1') 
ON DUPLICATE KEY UPDATE nickname ='1', location= '1', role= '1', yog= '1', interests= '1', favMoment= '1', gainThisYr= '1', futurePlans= '1', bio= '1' 
+0

右括号没有匹配的左括号。 – randomThought 2010-08-24 19:42:13

+0

+1:是的,查询缺少'ON DUPLICATE KEY UPDATE'中的字段之间的逗号, – 2010-08-24 19:42:21

+0

@TP:True,这会在添加逗号后变成另一个1064错误*,所以我在我编辑了格式化的答案。 – 2010-08-24 19:43:50

1

你永远不打开你的括号,你需要的字段

ON DUPLICATE KEY UPDATE **(**nickname ='1', location= '1', role= '1', yog= '1', interests= '1', favMoment= '1', gainThisYr= '1', futurePlans= '1', bio= '1')  
+0

根据文档,括号不是必需的:http://dev.mysql.com/doc/refman/5.0/en/insert-on-duplicate.html – 2010-08-24 19:44:31

1

如果您不使用之间的逗号逗号分隔列表以在最后一行更新?