- Kategorien:
Zeichenfolgen- und Binärfunktionen (Allgemein)
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.
Bemerkung
Im Gegensatz zu einigen Implementierungen der CONCAT_WS-Funktion überspringt die Snowflake-CONCAT_WS nicht NULL-Werte.
- Siehe auch:
Syntax¶
CONCAT_WS( <separator> , <expression> [ , <expression> ... ] )
Argumente¶
separatorThe separator must meet the same requirements as
expression.expressionThe input expressions must be all strings, or all binary values.
Rückgabewerte¶
The function returns a VARCHAR or BINARY value that contains the 2nd through Nth arguments, separated by the first argument.
Wenn eines der Argumente NULL ist, gibt die Funktion NULL zurück.
The data type of the returned value is the same as the data type of the input values.
Nutzungshinweise¶
Metadatenfunktionen wie GET_DDL akzeptieren nur Konstanten als Eingabe. Verkettete Eingaben generieren einen Fehler.
CONCAT_WS setzt Trennzeichen zwischen den Argumenten, außer nach dem letzten Argument. Wenn CONCAT_WS mit nur einem Argument nach dem Trennzeichen aufgerufen wird, wird kein Trennzeichen angehängt.
Sortierungsdetails¶
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.
Beispiele¶
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 |
+---------------------------------------+
Das folgende Beispiel zeigt, dass, die Funktion NULL zurückgibt, wenn ein Argument NULL lautet:
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 |
+-----------------------+