ALLBASE/SQL Reference Manual (36216-90216)

Chapter 8 239
Expressions
CAST Function
If input to CAST is NULL, then the result of the CAST operation is NULL.
ALLBASE/SQL supports implicit data conversion between:
Numeric data types to numeric data types
Character data types to character data types
Binary data types to binary data types
Binary data types to character data types
Character data types to binary data types
When CAST is used to do these conversions, all existing rules are applied.
When a number is converted, if the number does not fit within the target precision, an
overflow error occurs.
When converting from an approximate numeric to an exact numeric or from an exact
numeric to an exact numeric with less scale (integers have a scale of 0), the extra digits
of scale beyond the target scale are dropped without rounding the result.
Source Data Type Target Data Type
EN
a
AN
b
VC CHAR
(n)
B VB DATE TIME DT I TID
ENa
Y
c
Yc
Y
d
Yd Ed Ed Nd N N N N
ANb Yc Yc Yd Yd Ed Ed N N N N N
VARCHAR(n) Yd Yd Yc Yc Yc Yc Yc Yc Yc Yc Ed
CHAR(n) Yd Yd Yc Yc Yc Yc Yc Yc Yc Yc Ed
BINARY Ed Ed Yc Yc Yc Yc Ed Ed Ed Ed Ed
VARBINARY(n) Ed Ed Yc Yc Yc Yc Ed Ed Ed Ed Ed
DATE Ec Ec Yc Yc Ed Ed Yc N N N N
TIME Ec Ec Yc Yc Ed Ed N Yc N N N
DATETIME Ec Ec Yc Yc Ed Ed N N Yc N N
INTERVAL Yc Ec Yc Yc Ed Ed N N N Yc N
TID N N Ed Ed Ed Ed N N N N Yc
a. EN—Exact Numeric (SMALLINT, INT[EGER], DEC[IMAL][(p[,s])], NUMERIC[(p[,s])])
b. AN—Approximate Numeric (FLOAT[(p)] or DOUBLE PRECISION, REAL)
c. Implicit conversion also supported
d. Conversion supported only with CAST