Casts

The database server looks for a cast in the syscasts system catalog table to determine which function to use to convert the data type value to a different type. A cast performs the necessary operations for conversion from the data type to another data type. When two data types have different internal formats, the database server calls a cast function to convert one data type to another. For example, when you add an integer value to a decimal value, the database server performs a cast to change the integer into a decimal so that it can perform the addition.

The database server provides casts between the built-in data types. You might want to create additional casts to provide data conversion between an existing data type and an extended data type that you create. If the two data types have different internal formats, you must define a cast function to perform the data conversion. You must register the cast function with the CREATE FUNCTION statement and create the cast with the CREATE CAST statement before it can be used. For more information about casts, see Create user-defined casts.