SQL Tutorial SQL Advanced SQL Database SQL References

Oracle CONCAT() Function



The Oracle (PL/SQL) CONCAT() function is used to concatenate two strings together. This function only allows to concatenate two strings. To concatenate more than two strings together, multiple nested CONCAT() function calls can be used.

Syntax

CONCAT(string1, string2)

Parameters

string1 Required. Specify the first string to concatenate.
string2 Required. Specify the second string to concatenate.

Return Value

Returns the concatenated string.

Example 1:

The example below shows the usage of CONCAT() function.

CONCAT('SQL ', 'Tutorial')
Result: 'SQL Tutorial'

CONCAT('Sum is ', 25 + 25)
Result: 'Sum is 50'

CONCAT(CONCAT('Alpha ', 'Beta'), ' Gamma')
Result: 'Alpha Beta Gamma'

Example 2:

When two single quotes are used in a string, it creates a single quote character in the given string. See the example below:

CONCAT('Let''s ', 'learn Oracle')
Result: Let's learn Oracle

CONCAT('Let', '''s learn Oracle')
Result: Let's learn Oracle

Example 3:

Consider a database table called Employee with the following records:

EmpIDFirstNameLastName
1JohnSmith
2MarryKnight
3JoWilliams
4KimFischer
5RameshGupta
6HuangZhang

In the query below, the CONCAT() function is used to concatenate records of column FirstName and column LastName.

SELECT Employee.*, 
CONCAT(CONCAT(FirstName, ' '), LastName) AS FullName 
FROM Employee;

This will produce the result as shown below:

EmpIDFirstNameLastNameFullName
1JohnSmithJohn Smith
2MarryKnightMarry Knight
3JoWilliamsJo Williams
4KimFischerKim Fischer
5RameshGuptaRamesh Gupta
6HuangZhangHuang Zhang

❮ Oracle Functions