SQL CAST() function converts a value (of any type) into a specified datatype. This function converts an expression of one data type to another.
cast(expression as [datatype])
We will use students table with dummy data
Students Table columns
Students Table
select name, cast(marks as int) from students;
or
select name, marks::int from students;
*Note you can use :: followed by data type instead of typing cast *
Lets convert marks from a float to a char() of 3 characters. Try it out yourself before checking the answer
select name, cast(marks as char(3)) from students;
CAST in SQL is a function to explicitly convert a value of one data type to another.
The above is the detailed content of Cast for type conversion in SQL. For more information, please follow other related articles on the PHP Chinese website!