MySQL:CAST 在括号前不需要空格? [英] MySQL: CAST requires no space before parenthesis?
问题描述
在 MySQL 5.1 中,为什么这个 SQL 不能正常工作?
In MySQL 5.1, why won't this SQL work correctly?
SELECT CAST (20091023 as date);
[我刚刚自己找到了这个问题的答案——我会在下面自己回答——但这种行为太奇怪了,我想把它作为 StackOverflow 问答对捕获这样其他人就不会在同一问题上浪费时间.]
推荐答案
此代码有效:(注意CAST"后的空格已删除)
This code works: (note the space is removed after "CAST")
SELECT CAST(20091023 as date);
事实证明 MySQL 要求特定的内置函数列表在函数名和括号之间没有空格.有关更多信息,请参阅MySQL 手册中的此页面为什么存在这种行为.
Turns out MySQL requires that a specific list of built-in functions have no spaces between the function name and the parenthesis. See this page in the MySQL Manual for more info about why this behavior exists.
以下函数列表在 MySQL 5.1 中具有相同的限制(在以前的版本中还有更多):
The following list of functions have the same restriction in MySQL 5.1 (there are many more in previous versions):
ADDDATE
BIT_AND
BIT_OR
BIT_XOR
CAST
COUNT
CURDATE
CURTIME
DATE_ADD
DATE_SUB
EXTRACT
GROUP_CONCAT
MAX
MID
MIN
NOW
POSITION
SESSION_USER
STD
STDDEV
STDDEV_POP
STDDEV_SAMP
SUBDATE
SUBSTR
SUBSTRING
SUM
SYSDATE
SYSTEM_USER
TRIM
VARIANCE
VAR_POP
VAR_SAMP
希望这个答案可以帮助您避免浪费与我在此相同的时间!:-)
Hope this answer helps you avoid wasting the same amount of time I did on this! :-)
这篇关于MySQL:CAST 在括号前不需要空格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!