2012-10-03 131 views
-1

我不能更改表中的数据..数据更新 - SQL语法错误

UPDATE users 
    SET mem_expire = 2111-10-10 00:00:00 
    WHERE mem_expire = 0000-00-00 00:00:00; 

MySQL错误:

#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 '00:00:00 WHERE mem_expire = 0000-00-00 00:00:00' at line 2

我怎样才能解决这个问题?

+0

什么数据类型是mem_expire? –

+0

引用新日期'mem_expire ='2111-10-10 00:00:00''和旧的。 'WHERE mem_expire ='0000-00-00 00:00:00'; –

+0

[STR_TO_DATE](http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_str-to-date)是最好的方法,为任何日期格式提供灵活性你想使用而不是标准。 –

回答

1

日期字符串文字必须由行情,像这样被包围:

UPDATE users 
SET mem_expire = '2111-10-10 00:00:00' 
WHERE mem_expire = '0000-00-00 00:00:00'; 
+0

再次;非常感谢! –

5

尝试:

UPDATE users 
SET mem_expire = '2111-10-10 00:00:00' 
WHERE mem_expire = '0000-00-00 00:00:00'; 

您需要添加'(plings)

+0

Romo是正确的,因为这是一个你正在使用的字符串/值,所以你想确保用引号包装它,所以MySQL不会试图将'0000-00-00 00:00:00'视为MySQL关键字,但是一个字符串。 – Webnet

+0

非常感谢! –