Oracle NVL2関数で NULLデータを置換えるサンプル

環境
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0
SQL*Plus: Release 12.2.0.1.0

構文
NVL2( 文字列 , 変換文字列1, 変換文字列2 )
文字列 がNULLの場合は、変換文字列2を返します。NULLでなければ、変換文字列1を返します。
NVL2を使用すると、指定された式がNULLかどうかに基づく問合せによって戻される値を判断できます。expr1がNULLでない場合、NVL2はexpr2を戻します。 expr1がNULLの場合、NVL2はexpr3を戻します。

使用例1
NULL文字列をNVL2関数で実行します
SQL構文

select
  nvl2( null, 'Aa', 'null' ) result
 from dual

結果
null

使用例2
文字列’study’をNVL2関数で実行します
SQL構文

select
  nvl2( 'study', 'ark', 'null' ) result
 from dual

結果
ark

Oracle

Posted by arkgame