- カテゴリ:
文字列とバイナリ関数 (一般)
CONCAT_WS¶
Concatenates two or more strings, or concatenates two or more binary values, and uses the first argument as a delimiter between the following strings.
注釈
CONCAT_WS 関数の一部の実装とは異なり、Snowflake CONCAT_WS 関数は NULL 値をスキップしません。
- こちらもご参照ください。
構文¶
CONCAT_WS( <separator> , <expression> [ , <expression> ... ] )
引数¶
separatorThe separator must meet the same requirements as
expression.expressionThe input expressions must be all strings, or all binary values.
戻り値¶
The function returns a VARCHAR or BINARY value that contains the 2nd through Nth arguments, separated by the first argument.
いずれかの引数が NULL の場合、関数は NULL を返します。
The data type of the returned value is the same as the data type of the input values.
使用上の注意¶
GET_DDL などのメタデータ関数は、入力として定数のみを受け入れます。連結入力はエラーを生成します。
CONCAT_WS は、最後の引数の後ではなく、引数の間に区切り文字を置きます。区切り文字の後に引数を1つだけ指定して CONCAT_WS を呼び出すと、区切り文字は追加されません。
照合順序の詳細¶
The collation specifications of all input arguments must be compatible.
The collation of the result of the function is the highest-precedence collation of the inputs.
例¶
Call the CONCAT_WS function to concatenate three strings with a comma separator:
SELECT CONCAT_WS(',', 'one', 'two', 'three');
+---------------------------------------+
| CONCAT_WS(',', 'ONE', 'TWO', 'THREE') |
|---------------------------------------|
| one,two,three |
+---------------------------------------+
次の例は、引数のいずれかが NULL の場合は関数が NULL を返すことを示しています。
SELECT CONCAT_WS(',', 'one', NULL, 'two');
+------------------------------------+
| CONCAT_WS(',', 'ONE', NULL, 'TWO') |
|------------------------------------|
| NULL |
+------------------------------------+
The following example shows that when there is only one string to concatenate, the CONCAT_WS function doesn't append a separator:
SELECT CONCAT_WS(',', 'one');
+-----------------------+
| CONCAT_WS(',', 'ONE') |
|-----------------------|
| one |
+-----------------------+