Categorias:

Funções de cadeia de caracteres e binários (General)

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:

CONCAT

Sintaxe

CONCAT_WS( <separator> , <expression> [ , <expression> ... ] )
Copy

Argumentos

separator

The separator must meet the same requirements as expression.

expression

The 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

Exemplos

Call the CONCAT_WS function to concatenate three strings with a comma separator:

SELECT CONCAT_WS(',', 'one', 'two', 'three');
Copy
+---------------------------------------+
| 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');
Copy
+------------------------------------+
| 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');
Copy
+-----------------------+
| CONCAT_WS(',', 'ONE') |
|-----------------------|
| one                   |
+-----------------------+