- Categorias:
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.
Nota
Ao contrário de algumas implementações da função CONCAT_WS, a função CONCAT_WS do Snowflake não pula valores NULL.
- Consulte também:
Sintaxe¶
CONCAT_WS( <separator> , <expression> [ , <expression> ... ] )
Argumentos¶
separatorThe separator must meet the same requirements as
expression.expressionThe input expressions must be all strings, or all binary values.
Retornos¶
The function returns a VARCHAR or BINARY value that contains the 2nd through Nth arguments, separated by the first argument.
Se algum argumento for NULL, a função retornará NULL.
The data type of the returned value is the same as the data type of the input values.
Notas de uso¶
Funções de metadados tais como GET_DDL aceitam apenas constantes como entrada. A entrada concatenada gera um erro.
CONCAT_WS coloca os separadores entre os argumentos, não depois do último argumento. Se CONCAT_WS é chamado com apenas um argumento após o separador, então nenhum separador é anexado.
Detalhes do agrupamento¶
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.
Exemplos¶
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 |
+---------------------------------------+
O exemplo a seguir mostra que se qualquer argumento for NULL, a função retornará 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 |
+-----------------------+