How to display the bit(1) fields in MySQL?



Let us first create a table. Here, our columns is of type bit(1) −

mysql> create table DemoTable (    isCaptured bit(1) ); Query OK, 0 rows affected (1.00 sec)

Insert some records in the table using insert command −

mysql> insert into DemoTable values(0); Query OK, 1 row affected (0.26 sec) mysql> insert into DemoTable values(1); Query OK, 1 row affected (0.27 sec) mysql> insert into DemoTable values(0); Query OK, 1 row affected (0.47 sec) mysql> insert into DemoTable values(1); Query OK, 1 row affected (0.29 sec)

Following is the query to display all records from the table using select statement −

mysql> select *from DemoTable;

This will produce the following output −

+------------+ | isCaptured | +------------+ |            | |          | | | | | +------------+ 4 rows in set (0.00 sec)

Here is the query to see bit(1) fields in MySQL to display the fields −

mysql> select isCaptured+0 AS Visible from DemoTable;

This will produce the following output −

+---------+ | Visible | +---------+ | 0 | | 1 | | 0 | | 1 | +---------+ 4 rows in set (0.05 sec)
Updated on: 2019-07-30T22:30:25+05:30

784 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements