How do you concatenate in SQL

CONCAT

The CONCAT function concatenates two strings and returns the result string. To concatenate more than two strings, use nested CONCAT functions. The concatenation operator () between two strings produces the same results as the CONCAT function.

For the CONCAT function and the concatenation operator, the result of concatenation is null if one or both of the strings are null.

syntax

Argument

string1, string2

Both arguments can be strings or fixed-length or variable-length expressions.

Return type

CONCAT returns a string. The data type of the string is the same type as the input arguments.

Examples

The following example concatenates two character literals:

The following query uses the CONCAT operator instead and produces the same result:

The following example uses two CONCAT functions to concatenate three strings:

To concatenate columns that may contain null values, use The Expression NVL. The following example uses NVL to return a 0 if NULL is found.

The following query concatenates CITY and STATE values ​​from the VENUE table:

The following query uses nested CONCAT functions. The query concatenates CITY and STATE values ​​from the table, but separates the result string with a comma and a space: