阅读原文:https://www.cnblogs.com/blogxiao/p/9251460.html

1.在mysql中null 不能使用任何运算符与其他字段或者变量(函数、存储过程)进行运算。若使用运算数据就可能会有问题。

2.应该使用 is NULL 判断:

  创建一个user表:id 主健 name 可以为空  

  select * from user;

  insert into user values('33',null);  # 创建一条name为空的数据

  insert into user values('222','');  # 创建一条为空字符的数据

       update workload_pattern set mss = 0 where mss is null;    # 更新null值为0

  

用isnull判断是否为空:只有name 为null 的时候 ISNULL(exp) 函数的返回值为1 ,空串和有数据都为0;

 过滤到null的sql 语句 还用可以用  select * from user where name is not null;

或者  select * from user where ISNULL(name)=0;

3. 同时剔除null 和 空字符串 

select * from user where ISNULL(name)=0 and LENGTH(trim(name))>0;

4 在函数或者存储过程中判断是否为null 或者 空字符串

1
2
3
4
5
6
SELECT id,name,
    CASE
        WHEN (ISNULL(NAME)=1) || (LENGTH(trim(NAME))=0) THEN  'aaa'
    END
FROM
    USER

 

posted on 2021-06-29 11:35  51core  阅读(806)  评论(0)    收藏  举报