我们可以在 MySQL 查询中使用 SELECT NULL 语句吗?

mysqlmysqli database

是的,我们可以在 MySQL 查询中使用 SELECT NULL 语句。让我们首先创建一个表 −

mysql> create table DemoTable
(
   Name varchar(100)
);
Query OK, 0 rows affected (0.49 sec)

使用 insert 插入命令在表中插入一些记录 −

mysql> insert into DemoTable values('Chris');
Query OK, 1 row affected (0.47 sec)
mysql> insert into DemoTable values('Mike');
Query OK, 1 row affected (0.23 sec)
mysql> insert into DemoTable values('Sam');
Query OK, 1 row affected (0.19 sec)
mysql> insert into DemoTable values('Bob');
Query OK, 1 row affected (0.27 sec)
mysql> insert into DemoTable values('David');
Query OK, 1 row affected (0.11 sec)

使用 select 语句显示表中的所有记录 −

mysql> select *from DemoTable;

这将产生以下输出 −

+-------+
| Name  |
+-------+
| Chris |
| Mike  |
| Sam   |
| Bob   |
| David |
+-------+
5 rows in set (0.00 sec)

以下是实现 SELECT NULL 的查询 −

mysql> select null from DemoTable where Name='Mike';

这将产生以下输出 −

+------+
| NULL |
+------+
| NULL |
+------+
1 row in set (0.00 sec)


相关文章