MySQL查询仅替换表中的NULL值?
为此,可以将ISNULL属性用于MySQL中的空值。让我们首先创建一个表-
mysql> create table DemoTable ( Name varchar(100) );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable values('Robert');
mysql> insert into DemoTable values(null);
mysql> insert into DemoTable values('David');
mysql> insert into DemoTable values(null);
mysql> insert into DemoTable values('Robert');使用select语句显示表中的所有记录-
mysql> select *from DemoTable;
这将产生以下输出-
+--------+ | Name | +--------+ | Robert | | NULL | | David | | NULL | | Robert | +--------+ 5 rows in set (0.00 sec)
以下是查询以替换表中的空值-
mysql> update DemoTable set Name=IF(Name IS NULL,'Please Enter a Name',Name); Rows matched: 5 Changed: 2 Warnings: 0
让我们再次检查表记录-
mysql> select *from DemoTable;
这将产生以下输出-
+---------------------+ | Name | +---------------------+ | Robert | | Please Enter a Name | | David | | Please Enter a Name | | Robert | +---------------------+ 5 rows in set (0.00 sec)
热门推荐
10 秋分祝福语简短文案
11 60岁长辈祝福语简短
12 猪年元旦祝福语简短创意
13 学霸毕业祝福语简短
14 学生祝福语简短古诗句
15 新大学开学祝福语简短
16 14年祝福语简短情话
17 新年祝福语大全简短老师
18 祝福语对联文案简短大气