User Tools

Site Tools


Sidebar

Translations of this page:



最近の更新



Tag Cloud

en:50_dialy:2024:04:12

2024.04.12 MySQL BIT Field

The BIT field values are not displayed in MySQL.
It's because BIT values are characters that cannot be printed…
To see them, add UNSIGNED.
※ Specifying UNSIGNED allows only positive numbers to be stored.

mysql> desc test;
+---------+---------+------+-----+---------+----------------+
| Field   | Type    | Null | Key | Default | Extra          |
+---------+---------+------+-----+---------+----------------+
| id      | int(11) | NO   | PRI | NULL    | auto_increment |
| name    | text    | YES  |     | NULL    |                |
| enabled | bit(1)  | YES  |     | NULL    |                |
+---------+---------+------+-----+---------+----------------+
3 rows in set (0.00 sec)
mysql> insert into test (name,enabled) VALUES('AAA',b'1');
Query OK, 1 row affected (0.01 sec)

mysql> insert into test (name,enabled) VALUES('BBB',b'0');
Query OK, 1 row affected (0.00 sec)

mysql> select * from test;
+----+------+---------+
| id | name | enabled |
+----+------+---------+
| 1 | AAA | |
| 2 | BBB | |
+----+------+---------+
2 rows in set (0.00 sec)

To See the Display

mysql> select id,name, cast(enabled as UNSIGNED) as enabled from test;
+----+------+---------+
| id | name | enabled |
+----+------+---------+
|  1 | AAA  |       1 |
|  2 | BBB  |       0 |
+----+------+---------+
2 rows in set (0.01 sec)
en/50_dialy/2024/04/12.txt · Last modified: 2024/05/02 17:29 by matsui