为此,请使用IS NULL属性。让我们首先创建一个表-
mysql> create table DemoTable ( EmployeeName varchar(100), EmployeeAge int );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable values('Chris',32); mysql> insert into DemoTable values('David',45); mysql> insert into DemoTable values('Bob',NULL); mysql> insert into DemoTable values('Sam',28);
使用select语句显示表中的所有记录-
mysql> select *from DemoTable;
这将产生以下输出-
+--------------+-------------+ | EmployeeName | EmployeeAge | +--------------+-------------+ | Chris | 32 | | David | 45 | | Bob | NULL | | Sam | 28 | +--------------+-------------+ 4 rows in set (0.00 sec)
检索NULL的对应值-
mysql> select *from DemoTable where EmployeeAge IS NULL;
这将产生以下输出-
+--------------+-------------+ | EmployeeName | EmployeeAge | +--------------+-------------+ | Bob | NULL | +--------------+-------------+ 1 row in set (0.00 sec)