The concatenation function is one of the very useful functions used in any language with a variety of use cases. For example, if you want to concatenate the first name and last name of a person and display it as a full name in the output, this function will help you.
Teradata has two options to perform the string concatenation operation. In both cases, the result will be the same. The two methods are,
- Using ‘||’ operator
- Using CONCAT() function
1 – Concatenation using || operator
Let us take an example where you want to concatenate the name, department name, and location of an employee and display it together in the output. This will be used in case if the system wants to display these details together in a report.
Name – Charles
Department – R&D
Location – Chennai
SELECT 'Charles' || ' , ' || 'R&D department' || ' , ' || 'Chennai' as EmpDetails;
Output
2 – Concatenation using CONCAT function
In the previous example, we saw how to concatenate strings using the ‘||’ operator. In this example, let us do the same using the CONCAT function. The function will accept n number of strings to concatenate with comma as the separator in between
Name – Charles
Department – R&D
Location – Chennai
SELECT CONCAT('Charles',' , ','R&D department',' , ','Chennai') as EmpDetails;
Output
Also read,