zoukankan      html  css  js  c++  java
  • MySQL NULL 值处理

    为了处理这种情况,MySQL提供了三大运算符:

    • IS NULL: 当列的值是 NULL,此运算符返回 true。
    • IS NOT NULL: 当列的值不为 NULL, 运算符返回 true。
    • <=>: 比较操作符(不同于=运算符),当比较的的两个值为 NULL 时返回 true。

    关于 NULL 的条件比较运算是比较特殊的。你不能使用 = NULL 或 != NULL 在列中查找 NULL 值 。

    在 MySQL 中,NULL 值与任何其它值的比较(即使是 NULL)永远返回 false,即 NULL = NULL 返回false 。

    MySQL 中处理 NULL 使用 IS NULL 和 IS NOT NULL 运算符。

    注意:

    select * , columnName1+ifnull(columnName2,0) from tableName;

     columnName1,columnName2 为 int 型,当 columnName2 中,有值为 null 时,columnName1+columnName2=null, ifnull(columnName2,0) 把 columnName2 中 null 值转为 0。

  • 相关阅读:
    T-SQL基础(1)
    shell命令--chage
    Oracle SQL Lesson (11)
    shell命令--chpasswd
    Oracle SQL Lesson (10)
    shell命令--passwd
    Oracle SQL Lesson (9)
    shell命令--usermod
    Spring中的工厂模式和单例模式
    Oracle SQL Lesson (8)
  • 原文地址:https://www.cnblogs.com/loaderman/p/10167340.html
Copyright © 2011-2022 走看看