nvl函數用法,nvl函數

來源:互聯網
上載者:User

nvl函數用法,nvl函數

一NVL函數是一個空值轉換函式

NVL(運算式1,運算式2)

如果運算式1為空白值,NVL返回值為運算式2的值,否則返回運算式1的值。該函數的目的是把一個空值(null)轉換成一個實際的值。其運算式的值可以是數字型、字元型和日期型。但是運算式1和運算式2的資料類型必須為同一個類型。

對數字型: NVL( comm,0);

對字元型 NVL( TO_CHAR(comm), 'No Commission')

對日期型 NVL(hiredate,' 31-DEC-99')

 

實用例子:

查詢某個員工年薪,如果為空白則用0代替

select (sal+nvl(comm,o))*12 from emp where emp.pno=:pno;

這裡,comm是未定義的變數,代指數字類型。 nvl返回為0.

二 NVL2(運算式1,運算式2,運算式3)

如果運算式1為空白,返回值為運算式3的值。如果運算式1不為空白,返回值為運算式2的值。

例如 NVL2(comm,'sal+comm',sal)

NVL2函數測試comm

如果comm為空白,就返回sal 的值。如果 comm 不為空白(null),就返回運算式 sal+comm的值。

相關關鍵詞:
相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.