totn MariaDB Functions

MariaDB: CONCAT Function

This MariaDB tutorial explains how to use the MariaDB CONCAT function with syntax and examples.

Description

The MariaDB CONCAT function allows you to concatenate two or more expressions together.

Syntax

The syntax for the CONCAT function in MariaDB is:

CONCAT( expression1, expression2, ... expression_n )

Parameters or Arguments

expression1, expression2, ... expression_n
The expressions to concatenate together.

Note

  • If expression is a numeric value, it will be converted by the CONCAT function to a binary string.
  • If all expressions are nonbinary strings, the CONCAT function will return a nonbinary string.
  • If any of the expressions is a binary string, the CONCAT function will return a binary string.
  • If any of the expressions is a NULL, the CONCAT function will return a NULL value.
  • See also the CONCAT_WS function.

Applies To

The CONCAT function can be used in the following versions of MariaDB:

  • MariaDB 10

Example

Let's look at some MariaDB CONCAT function examples and explore how to use the CONCAT function in MariaDB.

For example:

SELECT CONCAT('Tech', 'On', 'The', 'Net', '.com');
Result: 'TechOnTheNet.com'

SELECT CONCAT('The answer is ', 10);
Result: 'The answer is 10'

SELECT CONCAT('The answer is ', 5+5);
Result: 'The answer is 10'

SELECT CONCAT('The answer is ', '5+5');
Result: 'The answer is 5+5'

SELECT CONCAT('TechOnTheNet.com', NULL);
Result:  NULL

You can also concatenate expressions together in MariaDB by placing the strings next to each other.

For example:

SELECT 'Tech' 'On' 'The' 'Net' '.com';
Result: 'TechOnTheNet.com'

SELECT 'The answer is ' '10';
Result:  'The answer is 10'

SELECT 'The answer is ' '5+5';
Result:  'The answer is 5+5'

Using the above method of concatenation, each of the expressions must be a string.