gpt4 book ai didi

mysql - 无法在 MySQL 中使用 ENUM 变量类型选择没有双引号的行

转载 作者:行者123 更新时间:2023-11-29 11:44:46 25 4
gpt4 key购买 nike

如何在不使用双引号(“1”)的情况下选择行。我正在设计枚举类型的 status 列。

status
enum('0', '1')

我的查询:

 SELECT * FROM `user` WHERE activation_key='123456' AND status="1";

结果:

 Display 1 row

我正在尝试:

 SELECT * FROM `user` WHERE activation_key='123456' AND status=1;

结果:

Display 0 row

是否可以获取status列中不带双引号或单引号的数据?我是 MYSQL 的初学者,抱歉我的问题不好!

最佳答案

枚举值必须是带引号的字符串。要查询字符串,您必须将其括在引号中。

如果您使枚举值看起来像数字,则很容易将文字值与其内部索引号混淆。

numbers ENUM('0','1','2')

If you store 2, it is interpreted as an index value, and becomes '1' (the value with index 2). If you store '2', it matches an enumeration value, so it is stored as '2'. If you store '3', it does not match any enumeration value, so it is treated as an index and becomes '2' (the value with index 3).

mysql> INSERT INTO t (numbers) VALUES(2),('2'),('3');
mysql> SELECT * FROM t;
+---------+
| numbers |
+---------+
| 1 |
| 2 |
| 2 |
+---------+

更多详情ENUM in MySQL

关于mysql - 无法在 MySQL 中使用 ENUM 变量类型选择没有双引号的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35146439/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com