CAST in SQL
In SQL, the CAST
function is used to convert data from one data type to another. It's particularly useful when you need to ensure data compatibility or perform calculations involving different data types.
Syntax
CAST(expression AS data_type)
Example
SELECT CAST('123' AS INT);
This query converts the string '123' to an integer data type.
The CAST
function in SQL allows you to convert data between different data types, ensuring data consistency and compatibility in your queries.