下图中数据库中查询到的值有空值,包括空白值(“”)和null
有人建议使用isnull()函数,但是该函数只能替换null无法替换空白的值。
可以使用下面的sql 语句对null和空白值都替换为其他的值。
select (case when (telphone is null or telphone='') then '暂无' else telphone end) as telphone,(case when (name is null or name='') then '暂无' else name end) as name,(case when (createdate is null or createdate='') then '暂无' else createdate end) as createdate,(case when ([address] is null or [address]='') then '暂无' else [address] end) as [address] from user_detail
上图中我们可以看到所有的null和空白值都替换为了“暂无”。
补充:sql查询时替换空值
目前我所知道的有三种方法:
select if(age is null,18,age) from student
2.1 isnull
select isnull(age,18) from student
2.2 coalesce
select coalesce(age,18) from student
以上为个人经验,希望能给大家一个参考,也希望大家多多支持本教程网。如有错误或未考虑完全的地方,望不吝赐教。