What is a cast?
A cast is a mechanism that converts a value from one
data type to another data type. Casts allow you to make comparisons
between values of different data types or substitute a value of one
data type for a value of another data type. supports
casts in the following types of expressions:
- Column expressions
- Constant expressions
- Function expressions
- SPL variables
- Host variables (ESQL)
- Statement local variable (SLV) expressions
To convert a value of one data type to another data type, a cast
must exist in the database or the database server. Informix® supports
the following types of casts:
- Built-in cast
- A built-in cast is a cast that is built into the database server. A built-in cast performs automatic conversions between different built-in data types.
- User-defined cast
- A user-defined cast often requires a cast function to handle conversions from one data type to another. To register and use a user-defined cast, you must use the CREATE CAST statement.
A user-defined cast is explicit if you include the EXPLICIT keyword when you create a cast with the CREATE CAST statement. (The default option is explicit.) Explicit casts are never invoked automatically. To invoke an explicit cast, you must use the CAST... AS keywords or the double colon (::) cast operator.
A user-defined cast is implicit if you include the IMPLICIT keyword when you create a cast with a CREATE CAST statement. The database server automatically invokes implicit casts at runtime to perform data conversions.
All casts are included in the syscasts system catalog table. For information about syscasts, see the Informix® Guide to SQL: Reference.