MariaDB CONCAT() Function
In MariaDB, CONCAT()
is a built-in string function that concatenates all argument lists and returns the result.
If you need to concatenate multiple strings using delimiters, please use the CONCAT_WS()
function.
MariaDB CONCAT()
Syntax
Here is the syntax of the MariaDB CONCAT()
function:
CONCAT(str1, str2, ..., strN)
Parameter Description
str1, str2, ..., strN
-
Required, at least one string should be specified; if one of the concatenated parameters is
NULL
, it will be returnedNULL
; when no string is specified, MariaDB will report an error:ERROR 1582 (42000): Incorrect parameter count in the call to native function 'CONCAT'
.
If you do not provide parameters, MariaDB will report an error: ERROR 1582 (42000): Incorrect parameter count in the call to native function 'CONCAT'
.
Return value
The MariaDB CONCAT()
function returns a string concatenated from all parameters.
If one of the arguments is NULL
, the CONCAT()
function will return NULL
.
If there is only one argument, the CONCAT()
function returns the argument itself.
MariaDB CONCAT()
Examples
Basic Example
The following statement uses the MariaDB CONCAT()
function to connect these fruit names Apple
, Peach
, Banana
:
SELECT CONCAT('Apple', 'Peach', 'Banana');
Output:
+------------------------------------+
| CONCAT('Apple', 'Peach', 'Banana') |
+------------------------------------+
| ApplePeachBanana |
+------------------------------------+
NULL
parameters
If the string list contains a NULL
value, CONCAT()
will return NULL
.
The following example illustrates this:
SELECT CONCAT('Apple', NULL, 'Banana');
Output:
+---------------------------------+
| CONCAT('Apple', NULL, 'Banana') |
+---------------------------------+
| NULL |
+---------------------------------+
Binary string
If you use a binary string, the CONCAT()
function also returns a binary string.
SELECT CONCAT(BINARY 'Apple', 'Peach');
Output:
+---------------------------------+
| CONCAT(BINARY 'Apple', 'Peach') |
+---------------------------------+
| ApplePeach |
+---------------------------------+
You can use the COLLATION()
function to check the collation of the results:
SELECT COLLATION(CONCAT(BINARY 'Apple', 'Peach'));
Output:
+--------------------------------------------+
| COLLATION(CONCAT(BINARY 'Apple', 'Peach')) |
+--------------------------------------------+
| binary |
+--------------------------------------------+
Conclusion
The MariaDB CONCAT()
function is used to concatenate multiple parameters and return the concatenated string.