CAST Function
In many cases, a database will automatically convert one data type into another when needed. On the other hand, there are instances when that is not the case, or when you want to explicitly specify what data type to change into. In these cases, you can use the CAST function. The syntax of the CAST function is as follows:
CAST (expression AS [data type])
where [data type] is a valid data type in the RDBMS you are working with.
Table Student
StudentID
|
First_Name
|
Marks
|
1
|
Anil
|
95.9
|
2
|
Sunil
|
93.5
|
3
|
Ram
|
80
|
4
|
sumit
|
70.1
|
Example
SELECT First_Name, CAST(Marks AS Integer) marks FROM Student_Score;
OutPut:
First_Name
|
Int_Marks
|
Anil
|
96
|
Sunil
|
94
|
Ram
|
80
|
sumit
|
70
|