I'm new to MySql. So I don't know many things like Casting of data types. How can I convert bool to int in MySql. And also how can I convert decimal to Int in MySql.
MySQL does not have a boolean (or bool) data type. Instead, it converts boolean values into integer data types (TINYINT). When you create a table with a boolean data type, MySQL outputs data as 0, if false, and 1, if true.
You can update boolean value using UPDATE command. If you use the BOOLEAN data type, MySQL internally convert it into tinyint(1). It can takes true or false literal in which true indicates 1 to tinyint(1) and false indicates 0 to tinyint(1).
Typecasting boolean to integer:
SELECT CAST(1=1 AS SIGNED INTEGER); /* 1 */
Same for decimal and strings:
SELECT CAST("1.23" AS SIGNED INTEGER); /* 1 */
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