我有一个表actor具有可为空的列first_name。我将特定行设置为null:

update actor set first_name=null where actor_id=201;
Query OK, 1 rows affected, 1 warning (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 1


然后,我尝试使用where子句中的null值查询该表,但什么也没有得到:

select * from actor where first_name is null;
Empty set (0.00 sec)


但是,如果我选择检查该列是否为空字符串,则会返回正确的值:

select * from actor where first_name = '';
[...]
1 row in set (0.00 sec)


存储引擎是MyISAM。为什么将空列设置为空字符串?

更新资料

我看到了1警告,但是mysql CLI没有显示任何警告。我该如何做呢?

也:

desc actor;
+-------------+----------------------+------+-----+-------------------+-----------------------------+
| Field       | Type                 | Null | Key | Default           | Extra                       |
+-------------+----------------------+------+-----+-------------------+-----------------------------+
| actor_id    | smallint(5) unsigned | NO   | PRI | NULL              | auto_increment              |
| first_name  | varchar(45)          | NO   |     | NULL              |                             |
| last_name   | varchar(45)          | NO   | MUL | NULL              |                             |
| last_update | timestamp            | NO   |     | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP |
+-------------+----------------------+------+-----+-------------------+-----------------------------+

最佳答案

从表描述中,看起来包括first_name的所有列都不为空。您确定它为可空列吗?

10-08 18:02