Updated on 2026-11-06 GMT+08:00

concat_ws

Concatenates multiple strings, separating them with a specified delimiter.

Syntax

concat_ws(string <separator>, string <str1>, string <str2>[,...]) 

or

concat_ws(string <separator>, array<string> <a>) 

Parameters

Parameter

Mandatory

Type

Description

separator

Yes

STRING

The delimiter.

str1, str2

Yes

STRING

At least 2 strings must be specified. If the input is of type BIGINT, DECIMAL, DOUBLE, or DATETIME, it is implicitly converted to STRING type before evaluation.

a

Yes

ARRAY

The elements in the array are of type STRING.

Return Values

Returns a value of type STRING.

  • If str1 or str2 is not of type STRING, BIGINT, DECIMAL, DOUBLE, or DATETIME, an error is returned.
  • If a parameter (the string to be concatenated) is NULL, that parameter is ignored.
  • If there are no input parameters (strings to be concatenated), NULL is returned.

Example Code

Concatenate strings ABC and DEF using :. Return ABC:DEF.

select concat_ws(':','ABC','DEF'); 

Any input parameter is NULL. Return avg:18.

select concat_ws(':','avg',null,'18'); 

Concatenate elements in the array array('name', 'lilei') using :. Return name:lilei.

select concat_ws(':',array('name', 'lilei'));