- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to convert bool to int in MySQL?n
To convert bool to int in MySQL, you can use CAST(). Let us first create a table:
mysql> create table convertBoolToIntDemo -> ( -> isYoung bool -> ); Query OK, 0 rows affected (0.69 sec)
Following is the query to insert some records in the table using insert command:
mysql> insert into convertBoolToIntDemo values(true); Query OK, 1 row affected (0.18 sec) mysql> insert into convertBoolToIntDemo values(false); Query OK, 1 row affected (0.09 sec) mysql> insert into convertBoolToIntDemo values(true); Query OK, 1 row affected (0.15 sec) mysql> insert into convertBoolToIntDemo values(false); Query OK, 1 row affected (0.18 sec)
Following is the query to display records from the table using select command:
mysql> select *from convertBoolToIntDemo;
This will produce the following output
+---------+ | isYoung | +---------+ | 1 | | 0 | | 1 | | 0 | +---------+ 4 rows in set (0.00 sec)
Following is the query to convert bool to int in MySQL:
mysql> select cast(isYoung=1 AS SIGNED INTEGER) from convertBoolToIntDemo;
This will produce the following output
+-----------------------------------+ | cast(isYoung=1 AS SIGNED INTEGER) | +-----------------------------------+ | 1 | | 0 | | 1 | | 0 | +-----------------------------------+ 4 rows in set (0.00 sec)
- Related Articles
- How to convert bool to int in MySQL?
- Bool to int conversion in C++
- Convert INT to DATETIME in MySQL?
- Convert string to bool in C#
- Convert number INT in minutes to TIME in MySQL?
- How to convert List to int[] in Java?
- How to convert int to String in java?
- How to convert int to string in Python?
- How to convert an int to string in C++?
- How to convert yyyymmdd in INT type to date?
- How to convert Int to Hex String in Kotlin?
- What should I do? Select int as currency or convert int to currency format in MySql?
- How to convert a String to an int in Java
- How to convert a string to int in Lua programming?
- Convert int to String in Java
- How to convert a string into int in C#?

Advertisements