Joins all strings in a parameter list or all elements in an array using a specified separator and returns the result as a string. CONCAT_WS is an additional function of MaxCompute V2.0.
Syntax
string concat_ws(string <separator>, string <str1>, string <str2>[,...])
string concat_ws(string <separator>, array<string> <a>)Parameters
| Parameter | Required | Type | Description |
|---|---|---|---|
separator | Yes | STRING | The separator to insert between joined values. If null, the function returns null. |
str1, str2, ... | Yes (at least two) | STRING | The strings to join. Values of the BIGINT, DECIMAL, DOUBLE, or DATETIME type are implicitly converted to STRING before joining. |
a | Yes | array\<string\> | An array whose elements are joined. Elements must be of the STRING type. |
Return value
Returns a value of the STRING or STRUCT type.
The following rules apply:
If
str1orstr2is not of the STRING, BIGINT, DECIMAL, DOUBLE, or DATETIME type, an error is returned.If no input parameters are provided, or if any input parameter is null, null is returned.
Examples
Example 1: Join name and hanmeimei using a colon (:).
-- Returns: name:hanmeimei
select concat_ws(':','name','hanmeimei');Example 2: One of the parameters is null.
-- Returns: null
-- The third argument is null, so the entire result is null.
select concat_ws(':','avg',null,'34');Example 3: Join the elements of array('name', 'hanmeimei') using a colon (:).
-- Returns: name:hanmeimei
select concat_ws(':',array('name', 'hanmeimei'));Related functions
CONCAT_WS is a string function. For more information about functions used to process and transform strings, see String functions.
该文章对您有帮助吗?