All Products
Search
Document Center

MaxCompute:CONCAT_WS

Last Updated:Jul 24, 2023

Concatenates all strings in a parameter or elements in an array by using the specified delimiter and returns the result. This function 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

  • separator: required. A delimiter of the STRING type.

  • str1 and str2: At least two strings must be specified. The values are of the STRING type. If the input values are of the BIGINT, DECIMAL, DOUBLE, or DATETIME type, the values are implicitly converted into values of the STRING type before calculation.

  • a: required. This parameter specifies an array. The elements in the array are of the STRING type.

Return value

A value of the STRING or STRUCT type is returned. The return value varies based on the following rules:

  • If the value of str1 or str2 is not of the STRING, BIGINT, DECIMAL, DOUBLE, or DATETIME type, an error is returned.

  • If no input parameters are available or an input parameter is set to null, null is returned.

Examples

  • Example 1: Concatenate the strings name and hanmeimei by using a colon (:). Sample statement:

    -- The return value is name:hanmeimei. 
    select concat_ws(':','name','hanmeimei');

    -

  • Example 2: An input parameter is set to null. Sample statement:

    -- The return value is null. 
    select concat_ws(':','avg',null,'34');
  • Example 3: Concatenate the elements in the array('name', 'hanmeimei') array by using colons (:). Sample statement:

    -- The return value is name:hanmeimei. 
    select concat_ws(':',array('name', 'hanmeimei'));

Related functions

CONCAT_WS is a string function. For more information about functions that are used to query strings and convert the format of strings, see String functions.