2010-08-24 108 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

如果您不使用之間的逗號逗號分隔列表以在最後一行更新?