MySQL concat function is one of the many functions in MySQL database, the syntax and usage of MySQL concat function are described below for your reference and learning.
How to use MySQL concat function:
CONCAT (STR1,STR2,...)
Returns the string that results from the connection parameter. If any one of the arguments is NULL, the return value is null.
Attention:
If all parameters are non-binary strings, the result is a non-binary string.
If the argument contains any twos binary string, the result is a binary string.
A numeric parameter is converted to an equal binary string format; To avoid this, you can use explicit type cast, for example:
SELECT CONCAT (CAST (Int_col as CHAR), Char_col)
The MySQL concat function can concatenate one or more strings, such as
- MySQL> select concat (' 10 ');
- +--------------+
- | Concat (' 10 ') |
- +--------------+
- | 10 |
- +--------------+
- 1 row in Set (0.00 sec)
- MySQL> select concat (' 11 ', ' 22 ', ' 33 ');
- +------------------------+
- | Concat (' 11 ', ' 22 ', ' 33 ') |
- +------------------------+
- | 112233 |
- +------------------------+
- 1 row in Set (0.00 sec)
MySQL's concat function will return NULL if one is null when the string is concatenated.
- MySQL> select concat (' One ', ' n ', null);
- +------------------------+
- | Concat (' One ', ' + ', null) |
- +------------------------+
- | NULL |
- +------------------------+
- 1 row in Set (0.00 sec)
The use of MySQL concat functions