MySQL CONCAT() Functions – String Functions

MySQL CONCAT() Functions: Syntax

CONCAT ( string1, string2, ..  )

MySQL CONCAT() Functions: Description

CONCAT() functions returns the concatenated string. You may have one or more arguments.

  • If all arguments are nonbinary strings, the result is a nonbinary string.
  • If the arguments include any binary strings, the result is a binary string.
  • A numeric argument is converted to its equivalent nonbinary string form.
  • CONCAT() returns NULL if any argument is NULL.

For quoted strings, concatenation can be performed by placing the strings next to each other.


MySQL CONCAT() Functions: Parameter

[table caption=”” width=”100%” colwidth=”15%||30%|55%” colalign=”left|lef|left”]
Name, Required /Optional, Description
string1,  Required, first parameter is must.
string2 , Required, second parameter is must.
stringN… , Optional, N number of strings can be passed as parameter.
[/table]


MySQL CONCAT() Functions: Output

[table caption=”” width=”100%” colwidth=”20%|80%” colalign=”left|left”]
Returns,
NULL, if any argument is NULL.
nonbinary string, If all arguments are nonbinary strings.
binary string, If the arguments include any binary strings.
[/table]


MySQL CONCAT() Functions: Available from

[table caption=”” width=”100%” colwidth=”25%|75%” colalign=”left|left”]
Version, MySQL 4.0
[/table]


MySQL CONCAT() Functions: Example 1

mysql> SELECT CONCAT('Tutorial', 'mines', '.net');
+-------------------------------------+
| CONCAT('Tutorial', 'mines', '.net') |
+-------------------------------------+
| Tutorialmines.net                   |
+-------------------------------------+
1 row in set (0.00 sec)
mysql> SELECT CONCAT('Tutorial', NULL , 'mines', '.net');
+--------------------------------------------+
| CONCAT('Tutorial', NULL , 'mines', '.net') |
+--------------------------------------------+
| NULL |
+--------------------------------------------+
1 row in set (0.01 sec)

mysql> SELECT CONCAT(14.3, 12.45, 78.0);
+---------------------------+
| CONCAT(14.3, 12.45, 78.0) |
+---------------------------+
| 14.312.4578.0 |
+---------------------------+
1 row in set (0.00 sec)

mysql> SELECT 'Tutorial' 'mines' '.net';
+-------------------+
| Tutorial |
+-------------------+
| Tutorialmines.net |
+-------------------+
1 row in set (0.00 sec)


Below is the mysql terminal screen for above code :


See all MySQL String functions MySQL 8 String Functions.


Related articles : LOCATE(), HEX(), CONCAT_WS(), LOWER(), LTRIM(), INSTR(), POSITION().


PHP Related articles : IMPLODE(), SUBSTR_COUNT(), SUBSTR_COMPARE(), PHP STRING FUNCTIONS(), JOIN().

You may also like...