MySQL Type Conversion
What is meant by Type Conversion?
Explanation
MySQL Type Conversion :
Type conversion takes place when operators are used with different types of operands in an expression. Some conversions are done implicitly and some need explicit conversions.
In MySQL the numbers are converted to strings and sometimes strings to numbers depending upon the condition.
Example :
Let us consider an example for converting a string to an integer.
mysql> Select 1+'11';
--> 12
Here the string '11' is converted to a number and the result of the expression is also a number.
Lets see another example for converting an integer to a string.
mysql> select concat(1, ' HIOX');
--> '1 HIOX'
We can convert or casting a number to a string explicitly. Here we use
CAST() or
CONCAT() function.
mysql> select 12, cast(12 as char);
--> 12, '12'
mysql> select 12, concat(12);
--> 12, '12'
The above examples shows how to use MySQL Type Conversion.