- Catégories :
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.
Note
Contrairement à certaines implémentations de la fonction CONCAT_WS, la fonction CONCAT_WS Snowflake n’ignore pas les valeurs NULL.
- Voir aussi :
Syntaxe¶
CONCAT_WS( <separator> , <expression> [ , <expression> ... ] )
Arguments¶
separatorThe separator must meet the same requirements as
expression.expressionThe input expressions must be all strings, or all binary values.
Renvoie¶
The function returns a VARCHAR or BINARY value that contains the 2nd through Nth arguments, separated by the first argument.
Si l’un des arguments est NULL, la fonction renvoie NULL.
The data type of the returned value is the same as the data type of the input values.
Notes sur l’utilisation¶
Les fonctions de métadonnées telles que GET_DDL n’acceptent que les constantes en entrée. L’entrée concaténée génère une erreur.
CONCAT_WS place des séparateurs entre les arguments, pas après le dernier argument. Si CONCAT_WS est appelé avec un seul argument après le séparateur, aucun séparateur n’est ajouté.
Détails du classement¶
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.
Exemples¶
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 |
+---------------------------------------+
L’exemple suivant montre que si un argument est NULL, la fonction renvoie 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 |
+-----------------------+