Learn how to use the Oracle/PLSQL CONCAT function with syntax and examples.
The Oracle/PLSQL CONCAT function allows you to concatenate two strings together.
The syntax for the Oracle/PLSQL CONCAT function is:
CONCAT( string1, string2 )
string1 is the first string to concatenate.
string2 is the second string to concatenate.
The CONCAT function can be used in the following versions of Oracle/PLSQL:
Let's look at some Oracle CONCAT function examples and explore how to use the CONCAT function in Oracle/PLSQL.
CONCAT('Tech on', ' the Net') Result: 'Tech on the Net' CONCAT('a', 'b') Result: 'ab'
Question: How can you use the CONCAT function to concatenate more than 2 strings together?
Answer: Since the CONCAT function will only let you concatenate 2 strings, you will need to nest multiple CONCAT functions to concatenate more than 2 strings together.
For example, to concatenate 3 strings, you could nest the CONCAT function as follows:
CONCAT( CONCAT( string1, string2 ), string3 )
Or you could nest the CONCAT function as follows, if you wanted to concatenate 4 strings:
CONCAT( CONCAT( CONCAT( string1, string2 ), string3 ), string4 )
Here is an example provided by Ruth that demonstrates how to nest multiple CONCAT functions to concatenate 6 strings:
CONCAT( CONCAT( CONCAT( CONCAT( CONCAT( 'I like ', t.type_desc_column), ' cake with '), t.icing_desc_column),' and a '), t.fruit_desc_column)
The CONCAT function is one method to concatenate strings in Oracle. An alternative to using the CONCAT function would be to use the || operator to catenatenate multiple strings, as follows:
'I like ' || t.type_desc_column || ' cake with ' || t.icing_desc_column || ' and a ' || t.fruit_desc_column