In MySQL is there a way to change the data type of a field, other than the original data type, without having an intermediate table involvement?
Have a look at 12.10. Cast Functions and Operators
The
CAST()
function takes an expression of any type and produces a result value of a specified type, similar toCONVERT()
.
CAST(expr AS type)
and
CONVERT(expr,type)
,CONVERT(expr USING transcoding_name)
CAST(expr AS type) is limited to convert to the following types:
If you need to convert to something else,, e.g., a boolean (BIT (1)), the following will work. Define a function with the return type you need and calculate your value inside the function body.
If you call this function from the definition of a view column, the type of the column will be the return type of your function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With