====== 2024.04.12 MySQL bitフィールド ====== MySQLでBITフィールド値が表示されない。 BIT値が印刷できない文字だから。。。 もし見るには、UNSIGNEDをつける。 ※UNSIGNED を指定すると正の数しか格納できなくなります。 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) ===== 表示を見るには ===== 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) {{tag>日記 mysql}}