mysql中的null与空字符串的区别

来源:互联网 发布:shopinfo.php 漏洞 编辑:程序博客网 时间:2024/05/20 07:17
null 表示"没有对(列)变量输入数据"
空字符串,则是"有对(列)变量输入数据"
区别:
    1、null的长度就是null,空字符串的长度就是0
    2、一串null数据比空字符串优先排序
    3、count(message)会将空字符串计数进去,但是不会将null数据计入
    4、可以使用绑定变量搜索某个空字符串,但是不可以这样搜索null

注意:select * from table where phone=null
这个 phone=null 的条件永远不为"真"
想查找 null 值,必须使用 is null 测试
select * from table where phone is null;
select * from table where phone='';
使用 order by expr asc,首先显示null值,desc 会显示最后一个
聚合函数,count(), min(), sum(), 将会忽略 null 值,但是 count(*) 将会计行数而不是单独的列值
原创粉丝点击