mySql  cast function

the mysql cast function converts a value of any type into a value that has a specified type.

the target type can be any one of the following types:binary, char,date,time,decimal,
signed

mysql cast() function syntax

         select    cast(expression as  type);  

the cast() function is often used to return a value with a specified type for comparison in the where,join and having clauses.


below is a selection from the "users" table:

useridfirstnamesalarybonus
1sandeep10,0001000
2ankit20,0002000
3ram30,0003000
4vikram12,0002000

mysql cast function example

the following statement explicitly convert an integer into a string and concatenate the string with another string.

               
               select    concat('my string value =',    cast (5 as char));

output :my string value =5 ;