为什么在MySQL中使用CAST时会出现语法错误? [英] Why do I get a syntax error when using CAST in MySQL?
问题描述
我正在使用MySQL Workbench v5.2.44 CE.我正在针对本地MySQL 5.5安装运行它.
I am using MySQL workbench v5.2.44 CE. I am running it against a local MySQL 5.5 install.
我正在尝试使用CAST
函数,但始终出现以下错误:
I am trying to use the CAST
function, but keep getting the following error:
语法错误,意外的INT_SYM
syntax error, unexpected INT_SYM
什么是源日期类型和目标日期类型都没有关系.只有当目标数据类型为DECIMAL
时,它才不会出现错误.这是一个示例:
It doesn't matter what the source and target date types are. The only time it doesn't give me an error is when the target datatype is DECIMAL
. Here is an example:
SELECT CAST(IFNULL(comboCount, 1) * COUNT(partID) AS INT) INTO comboCount
FROM productOption
我已经尝试了一切,但似乎没有任何效果.
I have tried everything, but nothing seems to work.
推荐答案
尝试在外部进行数学运算:
Try to do the math outside:
SELECT CAST(IFNULL(comboCount, 1) AS INT) * COUNT(partID) INTO comboCount
FROM productOption
如果这不起作用,请尝试将CAST
设置为UNSIGNED
;不是INT
.
If that doesn't work, try to CAST
as UNSIGNED
; not INT
.
这篇关于为什么在MySQL中使用CAST时会出现语法错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!