- 카테고리:
COALESCE¶
인자 중 첫 번째 NULL이 아닌 식을 반환하거나, 모든 인자가 NULL이면 NULL을 반환합니다.
구문¶
COALESCE( <expr1> , <expr2> [ , ... , <exprN> ] )
사용법 노트¶
데이터 정렬 세부 정보¶
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 |
+---------+---------+---------+-------------------------------------+