All pages
Powered by GitBook
1 of 1

Loading...

CONCAT

Concatenate strings. This function joins two or more string arguments into a single string. Returns NULL if any argument is NULL.

Syntax

Description

Returns the string that results from concatenating the arguments. May have one or more arguments. If all arguments are non-binary strings, the result is a non-binary string. If the arguments include any binary strings, the result is a binary string. A numeric argument is converted to its equivalent binary string form; if you want to avoid that, you can use an explicit type cast, as in this example:

CONCAT() returns NULL if any argument is NULL.

A NULL parameter hides all information contained in other parameters from the result. Sometimes this is not desirable; to avoid this, you can:

  • Use the function with an empty separator, because that function is NULL-safe.

  • Use to turn NULLs into empty strings.

Oracle Mode

In , CONCAT ignores .

Examples

Using IFNULL() to handle NULL values:

In :

See Also

This page is licensed: GPLv2, originally from

CONCAT(str1,str2,...)
CONCAT_WS()
IFNULL()
null
GROUP_CONCAT()
fill_help_tables.sql
SELECT CONCAT(CAST(int_col AS CHAR), char_col);
SELECT CONCAT('Ma', 'ria', 'DB');
+---------------------------+
| CONCAT('Ma', 'ria', 'DB') |
+---------------------------+
| MariaDB                   |
+---------------------------+

SELECT CONCAT('Ma', 'ria', NULL, 'DB');
+---------------------------------+
| CONCAT('Ma', 'ria', NULL, 'DB') |
+---------------------------------+
| NULL                            |
+---------------------------------+

SELECT CONCAT(42.0);
+--------------+
| CONCAT(42.0) |
+--------------+
| 42.0         |
+--------------+
SELECT CONCAT('The value of @v is: ', IFNULL(@v, ''));
+------------------------------------------------+
| CONCAT('The value of @v is: ', IFNULL(@v, '')) |
+------------------------------------------------+
| The value of @v is:                            |
+------------------------------------------------+
SELECT CONCAT('Ma', 'ria', NULL, 'DB');
+---------------------------------+
| CONCAT('Ma', 'ria', NULL, 'DB') |
+---------------------------------+
| MariaDB                         |
+---------------------------------+
Oracle mode
Oracle mode
Oracle mode