Informix Guide to SQL: Tutorial
Chapter 13: Casting Data Types
Home
Contents
Index
Master Index
New Book
Summary
A cast is a mechanism that allows you to compare values of different data types or substitute a value of one data type with another data type. INFORMIX-Universal Server supports both system-defined casts and user-defined casts. When a conversion operation requires the use of an explicit cast, you must use the
CAST AS
keyword or cast operator (::) to explicitly cast the value to be converted.
You can use an explicit cast to compare or substitute between values of a named row type and another row type when both row types have the same number of fields, and either the fields of the two row types are structurally equivalent or casts exist to perform the necessary conversions for corresponding field values that are not the same. Two unnamed row types that are structurally equivalent can be compared without an explicit cast.
You can use an explicit cast to convert from one collection type to another collection type when the element types of the two collection types are the same, or casts exist to perform conversions between any and all components of the element types that are not of the same data type.
A distinct type inherits all the functions and casts defined on its source type. Anywhere a cast exists to convert between a source type and particular data type, a cast also exists to convert between the distinct type (that is defined on the source type) and the particular data type. However, to compare or substitute between values of a distinct type and its source type, you must explicitly cast one type to the other.
When you wish to perform conversions between two data types that have the same storage structure, you can use the
CREATE CAST
statement without a conversion function. However, in some cases you must create a conversion function that you then register as a cast. You use a conversion function when the conversion is between two data types that have different storage structures or the data conversion involves the manipulation of the actual values.
Informix Guide to SQL: Tutorial
, version 9.1
Copyright © 1998, Informix Software, Inc. All rights reserved.