The data types of a result are determined by rules which are applied to the operands in an operation. This section explains those rules.
These rules apply to:
For the result data type of expressions that involve the operators /, *, + and -, see Expressions. For the result data type of expressions that involve the CONCAT operator, see With the concatenation operator.
The data type of the result is determined by the data type of the operands. The data types of the first two operands determine an intermediate result data type, this data type and the data type of the next operand determine a new intermediate result data type, and so on. The last intermediate result data type and the data type of the last operand determine the data type of the result. For each pair of data types, the result data type is determined by the sequential application of the rules summarized in the tables that follow.
If neither operand column allows nulls, the result does not allow nulls. Otherwise, the result allows nulls.
If the data type and attributes of any operand column are not the same as those of the result, the operand column values are converted to conform to the data type and attributes of the result. The conversion operation is exactly the same as if the values were assigned to the result. For example,
Numeric types are compatible with other numeric and character-string and graphic-string data types.
Character and graphic strings are compatible with other character and graphic strings when there is a defined conversion between their corresponding CCSIDs.
If one operand column is... | And the other operand is... | The data type of the result column is... |
---|---|---|
CHAR(x) | CHAR(y) | CHAR(z) where z = max(x,y) |
GRAPHIC(x) | GRAPHIC(y) or CHAR(y) | GRAPHIC(z) where z = max(x,y) |
VARCHAR(x) | VARCHAR(y) or CHAR(y) | VARCHAR(z) where z = max(x,y) |
VARCHAR(x) | GRAPHIC(y) | VARGRAPHIC(z) where z = max(x,y) |
VARGRAPHIC(x) | VARGRAPHIC(y) or GRAPHIC(y) or VARCHAR(y) or CHAR(y) | VARGRAPHIC(z) where z = max(x,y) |
CLOB(x) | CLOB(y) or VARCHAR(y) or CHAR(y) | CLOB(z) where z = max(x,y) |
CLOB(x) | GRAPHIC(y) or VARGRAPHIC(y) | DBCLOB(z) where z = max(x,y) |
DBCLOB(x) | CHAR(y) or VARCHAR(y) or CLOB(y) or GRAPHIC(y) or VARGRAPHIC(y) or DBCLOB(y) | DBCLOB(z) where z = max(x,y) |
The CCSID of the result graphic string will be derived based on the Conversion rules for operations that combine strings.
Binary strings are compatible only with other binary strings. Other data types can be treated as a binary-string data type by using the BINARY, VARBINARY, or BLOB scalar functions to cast the data type to a binary string.
If one operand column is... | And the other operand is... | The data type of the result column is... |
---|---|---|
BINARY(x) | BINARY(y) | BINARY(z) where z = max(x,y) |
VARBINARY(x) | VARBINARY(y) or BINARY(y) | VARBINARY(z) where z = max(x,y) |
BLOB(x) | BLOB(y) or VARBINARY(y) or BINARY(y) | BLOB(z) where z = max(x,y) |
A DATE type is compatible with another DATE type or any character string expression that contains a valid string representation of a date. A string representation must not be a CLOB. The data type of the result is DATE.
A TIME type is compatible with another TIME type or any character string expression that contains a valid string representation of a time. A string representation must not be a CLOB. The data type of the result is TIME.
A TIMESTAMP type is compatible with another TIMESTAMP type or any character string expression that contains a valid string representation of a timestamp. A string representation must not be a CLOB. The data type of the result is TIMESTAMP.
If one operand column is... | And the other operand is... | The data type of the result column is... |
---|---|---|
DATE | DATE, CHAR(y), or VARCHAR(y) | DATE |
TIME | TIME, CHAR(y), or VARCHAR(y) | TIME |
TIMESTAMP | TIMESTAMP, CHAR(y), or VARCHAR(y) | TIMESTAMP |
A DataLink is compatible with another DataLink. However, DataLinks with NO LINK CONTROL are only compatible with other DataLinks with NO LINK CONTROL; DataLinks with FILE LINK CONTROL READ PERMISSION FS are only compatible with other DataLinks with FILE LINK CONTROL READ PERMISSION FS; and DataLinks with FILE LINK CONTROL READ PERMISSION DB are only compatible with other DataLinks with FILE LINK CONTROL READ PERMISSION DB. The data type of the result is DATALINK. The length of the result DATALINK is the largest length of all the data types.
If one operand column is... | And the other operand is... | The data type of the result column is... |
---|---|---|
DATALINK(x) | DATALINK(y) | DATALINK(z) where z = max(x,y) |
A ROWID is compatible with another ROWID. The data type of the result is ROWID.
A user-defined distinct type is compatible only with the same user-defined distinct type. The data type of the result is the user-defined distinct type.
If one operand column is... | And the other operand is... | The data type of the result column is... |
---|---|---|
Distinct Type | Distinct Type | Distinct Type |