1.nvl函式
語法:nvl(expr1,expr2)
作用:如果expr1不是null,返回expr1,否則返回expr2
如下面例子所示
select nvl(null,1) from dual;--輸出結果為:1
select nvl(2,1) from dual;--輸出結果為:2
2.nvl2函式
語法:nvl(expr1,expr2,expr3)
作用:如果expr1不是null,返回expr2,否則返回expr3
如下面例子所示:
select nvl2(null,1,3) from dual;--輸出結果為:3
select nvl2(4,2,1) from dual;--輸出結果為:2
3.nullif函式
語法:nullif(expr1,expr2)
作用:比較兩個表示式,如果相等,返回null,否則返回第乙個表示式
如下面例子所示:
select nullif(1,1) from dual;--輸出結果為:空
select nullif(4,2) from dual;--輸出結果為:4
4.coalesce函式
語法:coalesce(expr1,expr2,...,exprn
)
coalesce(表示式1,表示式2,...表示式n)函式是對nvl函式的擴充套件。coalesce函式的功能是返回第乙個不為空的引數,引數個數不收限制。
如下面例子所示:
select coalesce(null,null,1,2,3) from dual;--輸出結果為:1
select coalesce(null,5,3,9) from dual;--輸出結果為:5
select coalesce(8,1,3,9) from dual;--輸出結果為:8
空值NULL處理
1.空值 null 處理 查詢籍貫為null同學 如果判斷乙個欄位的的值是不是null,需要使用is關鍵字,不能使用 select from tbstudent where stuaddress isnull 查詢籍貫不是null的所有同學 select from tbstudent where s...
處理Null(空)值
如果將null設定給物件的屬性,程式會報錯。例如 如果myblog.settitle null 程式會報錯。如果引數傳了乙個空值,那麼jdbc type對於所有的jdbc允許為空的列來說是必須指定的。解決方法 在引數中指定jdbctype屬性,這個屬性只在insert,update,delete的時...
Mysql的空值與NULL的區別
陷阱一 空值不一定為空 空值是乙個比較特殊的字段。在mysql資料庫中,在不同的情形下,空值往往代表不同的含義。這是mysql資料庫的一種特性。如在普通的字段中 字元型的資料 空值就是表示空值。但是如果將乙個空值的資料插入到timestamp型別的字段中,空值就不一定為空。此時為出現什麼情況呢 我先...