如何在 MySQL 中顯示 bit(1) 欄位?


首先,我們建立一個表。在此,我們的列型別為 bit(1) −

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

使用 insert 命令在表中插入一些記錄 −

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)

以下是使用 select 語句從表中顯示所有記錄的查詢 −

mysql> select *from DemoTable;

這將產生以下輸出 −

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

以下查詢將在 MySQL 中檢視 bit(1) 欄位以顯示欄位 −

mysql> select isCaptured+0 AS Visible from DemoTable;

這將產生以下輸出 −

+---------+
| Visible |
+---------+
| 0       |
| 1       |
| 0       |
| 1       |
+---------+
4 rows in set (0.05 sec)

更新日期:2019-07-30

678 次瀏覽

啟動您的 事業

完成課程即可獲得認證

開始學習
廣告
© . All rights reserved.