Summary:
See also: Data Types.
The runtime system performs data conversion implicitly without objection, as long as the data conversion is valid. For example, when you assign a number expression to a character variable, the runtime system converts the resulting number to a literal string.
Conversion rules apply to variable assignment, function parameters, and returned values.
Data conversions from or to character string values involve environment and locale settings like DBDATE, DBFORMAT.
When using the default exception handler, if a conversion error occurs, STATUS is zero and the target is set to zero for SMALLINT, INTEGER, SMALLFLOAT and FLOAT data types or NULL for all other data types.
The global STATUS variable is not set when a conversion error occurs unless you have enabled ANY ERROR detection with the WHENEVER instruction.The following table shows which pairs of data types are compatible.
Columns represent source data types and lines represent receiving data types.
c h a r |
v a r c h a r |
s t r i n g |
b i g i n t |
i n t e g e r |
s m a l l i n t |
t i n y i n t |
b o o l e a n |
f l o a t |
s m a l l f l o a t |
d e c i m a l |
m o n e y |
d a t e |
d a t e l i n e |
i n t e r v a l |
t e x t |
b y t e |
|
char | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1, 8 | 1, 9 | 1 | 1 | 1 | 15 |
varchar | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1, 8 | 1, 9 | 1 | 1 | 1 | 15 |
string | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1, 8 | 1, 9 | 1 | 1 | 1 | 15 |
bigint | 2, 3 | 2, 3 | 2, 3 | 3, 4 | 3, 4 | 3, 4 | 3, 4 | 11 | 15 | 15 | 15 | 15 | |||||
integer | 2, 3 | 2, 3 | 2, 3 | 3 | 3, 4 | 3, 4 | 3, 4 | 3, 4 | 11 | 15 | 15 | 15 | 15 | ||||
smallint | 2, 3 | 2, 3 | 2, 3 | 3 | 3 | 3, 4 | 3, 4 | 3, 4 | 3, 4 | 3, 11 | 15 | 15 | 15 | 15 | |||
tinyint | 2, 3 | 2, 3 | 2, 3 | 3 | 3 | 3 | 3, 4 | 3, 4 | 3, 4 | 3, 4 | 3, 11 | 15 | 15 | 15 | 15 | ||
boolean | 2, 3 | 2, 3 | 2, 3 | 3 | 3 | 3 | 3 | 3, 4 | 3, 4 | 3, 4 | 3, 4 | 3, 11 | 15 | 15 | 15 | 15 | |
float | 2, 3, 5 | 2, 3, 5 | 2, 3, 5 | 10 | 10 | 10 | 10 | 10 | 3 | 3 | 11 | 15 | 15 | 15 | 15 | ||
smallfloat | 2, 3, 5 | 2, 3, 5 | 2, 3, 5 | 5, 10 | 5, 10 | 10 | 10 | 10 | 5 | 3, 5 | 3, 5 | 5, 11 | 15 | 15 | 15 | 15 | |
decimal | 2, 3, 6 | 2, 3, 6 | 2, 3, 6 | 3 | 3 | 3 | 3 | 3 | 3, 6 | 3, 6 | 3, 6 | 3, 6 | 3, 11 | 15 | 15 | 15 | 15 |
money | 2, 3, 6 | 2, 3, 6 | 2, 3, 6 | 3 | 3 | 3 | 3 | 3 | 3, 6 | 3, 6 | 3, 6 | 3, 6 | 3, 11 | 15 | 15 | 15 | 15 |
date | 2 | 2 | 2 | 11 | 11 | 11 | 11 | 11 | 3,4,11 | 3,4,11 | 3,4,11 | 3,4,11 | 12, 14 | 15 | 15 | 15 | |
datetime | 2 | 2 | 2 | 15 | 15 | 15 | 15 | 15 | 15 | 15 | 15 | 15 | 13, 14 | 7, 14 | 15 | 15 | 15 |
interval | 2 | 2 | 2 | 15 | 15 | 15 | 15 | 15 | 15 | 15 | 15 | 15 | 15 | 15 | 3, 7 | 15 | 15 |
text | 1 | 1 | 1 | 15 | 15 | 15 | 15 | 15 | 15 | 15 | 15 | 15 | 15 | 15 | 15 | 15 | |
byte | 15 | 15 | 15 | 15 | 15 | 15 | 15 | 15 | 15 | 15 | 15 | 15 | 15 | 15 | 15 | 15 |