简体   繁体   English

MYSQL:在CONCAT()函数中使用列名会产生语法错误1064

[英]MYSQL: Using column name in CONCAT() function gives syntax error 1064

I have this query 我有这个查询

UPDATE `fitment_drums` SET `liters` = CONCAT(`liters`,'.0') WHERE `liters` LIKE '_'

Which results in this error: 导致此错误:

#1064 - You have an error in your SQL syntax; #1064-您的SQL语法有误; check the manual that corresponds to your MySQL server version for the right syntax to use near ''.0') FROM `fitment_drums` WHERE `liters` LIKE '_'' at line 1 请检查与您的MySQL服务器版本相对应的手册,以获取正确的语法,以在``.0''附近使用)。FROM`fitment_drums` WHERE`liters` LIKE'_'

When I substitute an ordinary string, eg. 当我替换一个普通的字符串,例如。 CONCAT ('asdf','.0') it works fine. CONCAT ('asdf','.0')正常工作。 I've tried using a select statement as an argument, and have also tried using a temporary table: 我尝试使用select语句作为参数,也尝试使用临时表:

CREATE TEMPORARY TABLE t1 (SELECT * FROM `fitment_drums` WHERE liters like '_') 
UPDATE `fitment_drums` SET liters = CONCAT(t1.liters,'.0') where t1.id = id

Ok, so I found the "solution". 好的,所以我找到了“解决方案”。 I was running the query in simulation mode, which results in the error posted above. 我在模拟模式下运行查询,这导致上面显示的错误。 So I backed up the table and executed the query in live mode, and it worked. 因此,我备份了表并以实时模式执行了查询,并且该查询成功了。 (for the record, I'm using phpMyAdmin) (出于记录,我使用的是phpMyAdmin)

Very strange. 很奇怪。

Thanks to everyone who tried to help! 感谢所有尝试提供帮助的人!

Since you revealed that you're using phpMyAdmin, you should know that temporary tables are dropped automatically as a database connection ends. 由于您已透露正在使用phpMyAdmin,因此应该知道在数据库连接结束时会自动删除临时表。

Each page view in phpMyAdmin is a separate PHP request, and thus a separate database connection. phpMyAdmin中的每个页面视图都是一个单独的PHP请求,因此是一个单独的数据库连接。

So if you CREATE TEMPORARY TABLE in phpMyAdmin, then the temp table did not exist anymore by the time you ran your UPDATE . 因此,如果您在phpMyAdmin中CREATE TEMPORARY TABLE ,那么在运行UPDATE时,该临时表已不存在。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM