concat Function

Syntax

returnvalue concat (source,[source*])

source ::= any*
returnvalue ::= boolean

Semantics

The concat function returns arg1 concatenated with arg2. Both arg1 and arg2 can be of any data type.

source
The input values that are joined to get a character string. This argument is implicitly cast to a sequence of strings.
returnvalue

Returns the character string made by joining its character string operands in the order given.

If any of the arguments is a sequence, then all the items are concatenated to the result in the order they appear in the sequence.

If all the arguments are empty sequence, then an empty sequence is returned.

If all the arguments are NULL, then a NULL is returned. This is because a NULL argument is converted to an empty string during concatenation unless all arguments are NULL, in which case the result is NULL. So NULL can result only from the concatenation of two or more NULL values.

Note:

For security/denial of service reasons the maximum number of chars of the returned string will be less than STRING_MAX_SIZE = 2^18 - 1 in chars i.e. 512kb. If the number of chars exceeds this number, then a runtime query exception is thrown.

Example 12-7 concat function

This example joins id, firstname, and lastname into a single string and provides the output. Notice that id, which is an integer type, also gets concatenated with the string values.

SELECT concat(id, firstname, lastname) AS name FROM users;
 +-------------+
 |    name     |
 +-------------+
 | 10JohnSmith |
 | 30PeterPaul |
 | 20MaryAnn   |
 +-------------+