oracle中的nvl函式

2021-08-01 20:56:46 字數 1242 閱讀 7004

格式為:

nvl( string1, replace_with)

功能:如果string1為null,則nvl函式返回replace_with的值,否則返回string1的值,如果兩個引數都為null ,則返回null。

注意事項:string1和replace_with必須為同一資料型別,除非顯式的使用to_char函式進行型別轉換。

例:nvl(to_char(numeric_column), 『some string』) 其中numeric_column代指某個數字型別的值。

例:nvl(yanlei777,0) > 0

nvl(yanlei777, 0) 的意思是 如果 yanlei777 是null, 則取 0值

通過查詢獲得某個欄位的合計值,如果這個值為null將給出乙個預設的預設值

例如:select nvl(sum(t.dwxhl),1)

from tb_jhde t

就表示如果sum(t.dwxhl) = null 就返回 1

另乙個有關的有用方法

declare i integer

select nvl(sum(t.dwxhl),1) into i from tb_jhde t where zydm=-1這樣就可以把獲得的合計值儲存到

變數i中,如果查詢的值為null就把它的值設定為預設的1

orcale中:

select nvl(rulescore,0) from zwjc_graderule where rulecode=』fwtd』;

如果記錄中不存在rulecode =』fwtd』的資料.則查不出資料.

select nvl(rulescore,0) into rule_score from zwjc_graderule where rulecode=』fwtd』;會報查不到資料的錯

select nvl(sum(rulescore),0) from zwjc_graderule where rulecode=』fwtd』;

如果記錄中不存在rulecode =』fwtd』的資料.還是可以得到一行列名為nvl(rulescore,0),值為0的資料.

select nvl(sum(rulescore),0) into rule_score from zwjc_graderule where rulecode=』fwtd』; 不會報錯

oracle在nvl函式的功能上擴充套件,提供了nvl2函式。

nvl2(e1, e2, e3)的功能為:如果e1為null,則函式返回e3,否則返回e2。

oracle中的nvl函式

格式為 nvl string1,replace with 功能 如果string1為null,則nvl函式返回replace with的值,否則返回string1的值,如果兩個引數都為null 則返回null。注意事項 string1和replace with必須為同一資料型別,除非顯式的使用to ...

Oracle中的NVL函式

oracle中函式nvl,nvl2,nullif,coalesce,這幾個函式用在各個型別上都可以。下面簡單介紹一下幾個函式的用法。1.nvl函式 nvl函式的格式如下 nvl expr1,expr2 含義是 如果oracle第乙個引數為空那麼顯示第二個引數的值,如果第乙個引數的值不為空,則顯示第乙...

Oracle中的NVL函式

oracle中函式以前介紹的字串處理,日期函式,數學函式,以及轉換函式等等,還有一類函式是通用函式。主要有 nvl,nvl2,nullif,coalesce,這幾個函式用在各個型別上都可以。下面簡單介紹一下幾個函式的用法。在介紹這個之前你必須明白什麼是oracle中的空值null 1.nvl函式 n...