2011-11-15 62 views
0
update tbl_user set tbl_user.Zoneid='(Select tbl_timezone.Zoneid from tbl_timezone where tbl_timezone.timezone='[UTC - 4:30] Venezuelan Standard Time')' Where tbl_user.userid='1' 

当我运行上面的查询我得到这个错误查询,在查询内部在MySQL

您的SQL语法错误;检查与您的MySQL服务器版本相对应的手册,以找到在'[UTC - 4:30]委内瑞拉标准时间'附近使用的正确语法')'其中tbl_user.userid ='1'在第1行

但是当我执行

update tbl_user set tbl_user.Zoneid='10' Where tbl_user.userid='1'; 

然后正常工作

以下查询的结果是10

Select tbl_timezone.Zoneid from tbl_timezone where tbl_timezone.timezone='[UTC - 4:30] Venezuelan Standard Time' 

什么错我的第一个查询。为什么我会收到错误

回答

1

您必须删除报价:

update tbl_user set tbl_user.Zoneid=(Select tbl_timezone.Zoneid from tbl_timezone where tbl_timezone.timezone='[UTC - 4:30] Venezuelan Standard Time') Where tbl_user.userid='1' 
1

在所有的SQL方言,单引号来分隔字符串:

SELECT this_is_a_column, 'This is a literal string' 
FROM table 

此外,还有是逃逸机制,使你可以写一个包含单引号的字符串

SELECT 'This string contains \'single\' quotes' 

在你的情况下:

  • 你假装在一个字符串中写代码,因此永远不会这样执行。
  • 您在字符串中写入未加引号的单引号,因此会出现语法错误。