CAST Function

CAST explicitly converts a value to a new type. For example:

SELECT * FROM upfall u
WHERE u.id = CAST('1' AS INTEGER);

When converting from text to numeric or date types, CAST offers little flexibility in dealing with different input data formats. For example, if the value you are casting is a string, the contents must conform to your database’s default text representation of the target data type.

Note

Most database brands have more useful conversion functions than CAST. SQL Server’s CONVERT function is one such example. See the sections on Datetime Conversions and Numeric Conversions.

Get SQL Pocket Guide, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.