array_join
Descriptionβ
Concatenates the elements of an array into a string.
Syntaxβ
array_join(array, sep[, null_replace_str])
Parametersβ
- 
array: the array whose elements you want to concatenate. Only the ARRAY data type is supported.
- 
sep: the delimiter that is used to separate the concatenated array elements. Only the VARCHAR data type is supported.
- 
null_replace_str: the string that is used to substituteNULLvalues. Only the VARCHAR data type is supported.
Return valueβ
Returns a value of the VARCHAR data type.
Usage notesβ
- 
The value of the arrayparameter must be a one-dimensional array.
- 
The arrayparameter does not support DECIMAL values.
- 
If you set the sepparameter toNULL, the return value isNULL.
- 
If you do not specify the null_replace_strparameter,NULLvalues are discarded.
- 
If you set the null_replace_strparameter toNULL, the return value isNULL.
Examplesβ
Example 1: Concatenate the elements of an array. In this example, the NULL value in the array is discarded, and the concatenated array elements are separated by underscores (_).
mysql> select array_join([1, 3, 5, null], '_');
+-------------------------------+
| array_join([1,3,5,NULL], '_') |
+-------------------------------+
| 1_3_5                         |
+-------------------------------+
Example 2: Concatenate the elements of an array. In this example, the NULL value in the array is substituted with NULL strings, and the concatenated array elements are separated by underscores (_).
mysql> select array_join([1, 3, 5, null], '_', 'NULL');
+---------------------------------------+
| array_join([1,3,5,NULL], '_', 'NULL') |
+---------------------------------------+
| 1_3_5_NULL                            |
+---------------------------------------+