The MySQL CAST() function converts a value of one type to a specified target data type. It allows developers to perform deterministic data transformations directly within SQL queries.
TARGET_TYPENULL if any required input argument evaluates to NULL.expression AS target_type-- Query demonstrating MySQL CAST() usage in production queries
SELECT CAST('123.45' AS DECIMAL(10,2)) AS num;
| num |
|---|
| 123.45 |
IFNULL() or COALESCE() if your input columns allow NULL values.WHERE clauses disables B-tree index lookups (causing full table scans). Use generated columns with indexes when querying heavily.Write a SQL query using CAST() to format or evaluate data retrieved from a database table.
Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.
Quick Access With