String Operators
Use the || string operator to concatenate two strings. The || operator converts operands of any datatype (except Binary) to String datatypes before concatenation:
Input Value | Return Value |
---|
'alpha' || 'betical' | alphabetical |
'alpha' || 2 | alpha2 |
'alpha' || NULL | alpha |
The || operator includes leading and trailing spaces. Use the LTRIM and RTRIM functions to trim leading and trailing spaces before concatenating two strings.
Nulls
The || operator ignores null values. However, if both values are NULL, the || operator returns NULL.
Example of String Operators
The following example shows an expression that concatenates employee first names and employee last names from two columns. This expression removes the spaces from the end of the first name and the beginning of the last name, concatenates a space to the end of each first name, then concatenates the last name:
LTRIM( RTRIM( EMP_FIRST ) || ' ' || LTRIM( EMP_LAST ))
EMP_FIRST | EMP_LAST | RETURN VALUE |
---|
' Alfred' | ' Rice ' | Alfred Rice |
' Bernice' | ' Kersins' | Bernice Kersins |
NULL | ' Proud' | Proud |
' Curt' | NULL | Curt |
NULL | NULL | NULL |
Note: You can also use the CONCAT function to concatenate two string values. The || operator, however, produces the same results in less time.