カテゴリ:

条件式関数

COALESCE

引数内の最初の非NULL 式を返します。またはすべての引数が NULL の場合は NULLを返します。

構文

COALESCE( <expr1> , <expr2> [ , ... , <exprN> ] ) 
Copy

使用上の注意

  • 可能であれば、同じ型の引数を渡します。異なる型の引数を渡すことは避けます。

  • 引数の1つが数値の場合、関数は、非数値文字列引数(例: 'a string')と型 NUMBER(18,5)の定数ではない文字列引数を 強制 します。

    定数ではない数値文字列引数で、 NUMBER(18,5)が数値を表すのに十分でない場合は、値を表すことができる型に引数を キャスト します。

照合順序の詳細

  • The collation specifications of all input arguments must be compatible.

  • The comparisons follow the collation based on the input arguments' collations and precedences.

  • The collation of the result of the function is the highest-precedence collation of the inputs.

SELECT column1, column2, column3, coalesce(column1, column2, column3) FROM (values (1, 2, 3 ), (null, 2, 3 ), (null, null, 3 ), (null, null, null), (1, null, 3 ), (1, null, null), (1, 2, null) ) v; +---------+---------+---------+-------------------------------------+ | COLUMN1 | COLUMN2 | COLUMN3 | COALESCE(COLUMN1, COLUMN2, COLUMN3) | |---------+---------+---------+-------------------------------------| | 1 | 2 | 3 | 1 | | NULL | 2 | 3 | 2 | | NULL | NULL | 3 | 3 | | NULL | NULL | NULL | NULL | | 1 | NULL | 3 | 1 | | 1 | NULL | NULL | 1 | | 1 | 2 | NULL | 1 | +---------+---------+---------+-------------------------------------+ 
Copy