- 类别:
字符串和二进制函数 (通用)
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 在实参之间放置分隔符,而不是在最后一个实参之后放置分隔符。如果在分隔符后仅使用一个实参调用 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 |
+-----------------------+