The operations that combine strings are concatenation, UNION, and UNION ALL. (These rules also apply to the MAX, MIN, VALUE, COALESCE, IFNULL, and CONCAT scalar functions and CASE expressions.) In each case, the CCSID of the result is determined at bind time, and the execution of the operation may involve conversion of strings to the coded character set identified by that CCSID.
The CCSID of the result is determined by the CCSIDs of the operands. The CCSIDs of the first two operands determine an intermediate result CCSID, this CCSID and the CCSID of the next operand determine a new intermediate result CCSID, and so on. The last intermediate result CCSID and the CCSID of the last operand determine the CCSID of the result string or column. For each pair of CCSIDs, the result CCSID is determined by the sequential application of the following rules:
Table 15. Selecting the Encoding Scheme of the Intermediate Result
| First Operand | Second Operand | |||
|---|---|---|---|---|
| SBCS Data | DBCS Data | Mixed Data | UCS-2 Data | |
| SBCS Data | See below | Second | Second | Second |
| DBCS Data | First | See below | Second | Second |
| Mixed Data | First | First | See below | Second |
| UCS-2 Data | First | First | First | See below |
Table 16. Selecting the CCSID of the Intermediate Result
| First Operand | Second Operand | ||||
|---|---|---|---|---|---|
| Column Value | Derived Value | Constant | Special Register | Host Variable | |
|
Column Value |
First |
First |
First |
First |
First |
|
Derived Value |
Second |
First |
First |
First |
First |
|
Constant |
Second |
Second |
First |
First |
First |
|
Special Register |
Second |
Second |
First |
First |
First |
|
Host Variable |
Second |
Second |
Second |
Second |
First |
However, a host variable containing data in a foreign encoding scheme is effectively converted to the native encoding scheme before it is used in any operation. The above rules are based on the assumption that this conversion has already occurred.
Note that an intermediate result is considered to be a derived value operand. For example, assume COLA, COLB, and COLC are columns with CCSIDs 37, 278, and 500, respectively. The result CCSID of COLA CONCAT COLB CONCAT COLC is determined as follows:
An operand of concatenation or the selected argument of the MAX, MIN, VALUE, COALESCE, IFNULL, and CONCAT scalar function is converted, if necessary, to the coded character set of the result string. Each string of an operand of UNION or UNION ALL is converted, if necessary, to the coded character set of the result column. Character conversion is necessary only if all of the following are true:
An error occurs if a character of a string cannot be converted or if the CCSID Conversion Selection Table is used but does not contain any information about the CCSID pair. A warning occurs if a character of a string is converted to the substitution character.