简体   繁体   English

为什么在MySQL中使用CAST时会出现语法错误?

[英]Why do I get a syntax error when using CAST in MySQL?

I am using MySQL workbench v5.2.44 CE. 我正在使用MySQL workbench v5.2.44 CE。 I am running it against a local MySQL 5.5 install. 我正在针对本地MySQL 5.5安装运行它。

I am trying to use the CAST function, but keep getting the following error: 我正在尝试使用CAST函数,但不断收到以下错误:

syntax error, unexpected INT_SYM 语法错误,意外的INT_SYM

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 . 当目标数据类型为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

If that doesn't work, try to CAST as UNSIGNED ; 如果这不起作用,请尝试CASTUNSIGNED ; not INT . 不是INT

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从MYSQL更新时为什么会出现语法错误? - Why do I get syntax error when I update from MYSQL? 通过电子邮件地址选择时,为什么会收到MySQL语法错误(1604)? - Why do I get a MySQL syntax error (1604) when I select by email address? 为什么我在 mySQL 中收到此语法错误? - Why I get this syntax error in mySQL? 为什么在将脚本加载到mysql时出现此错误? - Why do I get this error when loading a script into mysql? 为什么我在 MySQL 中遇到涉及 if 语句和 StackOverflow 上提到的异常抛出的语法错误? - Why do I get a syntax error in MySQL involving if statement and throwing of exception mentioned on StackOverflow? 将参数传递到MySqlParameter时,为什么会出现“ SQL语法错误”的提示? - Why do I get “You have an error in your SQL Syntax” when I pass parameters into MySqlParameter? 尝试将值插入具有“索引”列的表时,为什么会出现SQL语法错误? - Why do I get a SQL syntax error when I try to insert values into a table with a column named “index”? 为什么我使用 PHP 查询时出现错误 - Why do I get an error when I query using PHP 在phpmyadmin中使用varbinary(max)时,为什么会出现语法错误? - Why do I get a syntax error while I am using varbinary(max) in phpmyadmin? 每当我运行 MySQL 查询时,我都会收到语法错误 - When ever I run MySQL query I get syntax error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM