CAST: Converting to a Specific Data Type

How to:

The CAST function converts the value of its argument to a specified data type.


Top of page

x
Syntax: How to Convert to a Specific Data Type
CAST(expression AS data_type[(length)])

where:

arg

Any data type that can be converted to the result data type

Is the value to be converted.

data-type

Is the result data type: CHARACTER, CHARACTER VARYING, NUMERIC, DECIMAL, INTEGER, SMALLINT, FLOAT, REAL, DOUBLE PRECISION, DATE, TIME or TIMESTAMP.

length

Is an optional parameter of character data types.

This function returns the input value converted to the specified data type.



Example: Converting to a Specific Data Type

CAST converts a value to a specified data type. This example,

CAST(2.5 AS INTEGER)

returns 2.

This example,

CAST('3.333' AS FLOAT)

returns 3.333.


iWay Software