【问题标题】:mysql update ERROR 1054 : Unknown column 'x' in 'field list'mysql更新错误1054:“字段列表”中的未知列“x”
【发布时间】:2017-07-12 08:30:27
【问题描述】:

我试图更新 mysql 表并得到 ERROR 1054,然后发生了一些奇怪的事情。

表架构

CREATE TABLE `useraccount` (
  `userId` bigint(20) NOT NULL,
  `currentBalance` float NOT NULL,
  `currentDataBalance` bigint(20) NOT NULL,
  PRIMARY KEY (`userId`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8

我的表中有一个条目,即

mysql> select * from UserAccount;
+--------+----------------+--------------------+
| userId | currentBalance | currentDataBalance |
+--------+----------------+--------------------+
|      1 |              0 |               4296 |
+--------+----------------+--------------------+

我尝试更新 currentDataBalance 字段并得到错误

错误 1054 (42S22):“字段列表”中的未知列“253600l”

mysql> update UserAccount set currentDataBalance=253600l where userId=1;
ERROR 1054 (42S22): Unknown column '253600l' in 'field list'

然后我删除了更新值的最后一位(从 253600l 到 253600) 并且值得到了更新

mysql> update UserAccount set currentDataBalance=253600 where userId=1;
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0

然后我再次将值更改为以前的值(从 253600 到 2536001),这次更新了值。

mysql> update UserAccount set currentDataBalance=2536001 where userId=1;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

我在 stackoverflow 上浏览了许多与错误 1054 相关的帖子,但我没有得到相关答案。

【问题讨论】:

    标签: mysql sql mysql-5.7


    【解决方案1】:

    这个查询

    update UserAccount set currentDataBalance=253600l where userId=1;
    

    返回此错误:

    错误 1054 (42S22):“字段列表”中的未知列“253600l”

    因为你的“数字”中有一个字母:253600l,它把你的数字变成了一个字符串。由于这个字符串没有用引号括起来,MySQL假设它是一个名字数据库中的对象,在这种情况下是一列。 该对象不存在,因此出现此特定错误。

    【讨论】:

    • 感谢@Thoms 的详细解释!
    【解决方案2】:

    您的更新查询中有小拉丁字符“L”而不是数字“1”。由于您要设置的值看起来像 MySQL 的标识符,它会尝试查找具有该名称的列,但找不到它,这就是您收到此错误的原因。

    【讨论】:

      猜你喜欢
      • 2013-10-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-23
      相关资源
      最近更新 更多