CONCAT_WS

更新时间:
复制 MD 格式

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

ParameterRequiredTypeDescription
separatorYesSTRINGThe separator to insert between joined values. If null, the function returns null.
str1, str2, ...Yes (at least two)STRINGThe strings to join. Values of the BIGINT, DECIMAL, DOUBLE, or DATETIME type are implicitly converted to STRING before joining.
aYesarray\<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 str1 or str2 is 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.