检查MySQL列中的NULL或NOT NULL值
为此,请在MySQL中使用ISNOTNULL。让我们看看语法-
select yourColumnName IS NOT NULL from yourTableName;
如果该列没有NULL值,则上面的查询返回1,否则返回0。让我们首先创建一个-
create table DemoTable1408 -> ( -> FirstName varchar(30) -> );
使用insert在表中插入一些记录-
insert into DemoTable1408 values('Chris'); insert into DemoTable1408 values(''); insert into DemoTable1408 values(NULL); insert into DemoTable1408 values('David');
使用选择显示表中的所有记录-
select * from DemoTable1408;
这将产生以下输出-
+-----------+ | FirstName | +-----------+ | Chris | | | | NULL | | David | +-----------+ 4 rows in set (0.00 sec)
以下是检查NULL或NOTNULL的查询-
select FirstName IS NOT NULL from DemoTable1408;
这将产生以下输出-
+-----------------------+ | FirstName IS NOT NULL | +-----------------------+ | 1 | | 1 | | 0 | | 1 | +-----------------------+ 4 rows in set (0.00 sec)