MySQL 中 intvalue='1' 和 intvalue=1 的區別是什麼?


你需要使用 intvalue=1。語句 intvalue=’1’ 在內部會被 MySQL 轉換為 cast(‘1’ as int)。

我們首先建立一個表格 -

mysql> create table DemoTable1566
   -> (
   -> intvalue int
   -> );
Query OK, 0 rows affected (0.64 sec)

使用 insert 命令向表格中插入一些記錄 -

mysql> insert into DemoTable1566 values(1);
Query OK, 1 row affected (0.15 sec)
mysql> insert into DemoTable1566 values(55);
Query OK, 1 row affected (0.08 sec)
mysql> insert into DemoTable1566 values(75);
Query OK, 1 row affected (0.32 sec)
mysql> insert into DemoTable1566 values(90);
Query OK, 1 row affected (0.19 sec)

使用 select 語句從表格中顯示所有記錄 -

mysql> select * from DemoTable1566;

這會產生以下輸出 -

+----------+
| intvalue |
+----------+
|        1 |
|       55 |
|       75 |
|       90 |
+----------+
4 rows in set (0.00 sec)

這是實現 intvalue=1 的查詢 -

mysql> select * from DemoTable1566 where intvalue=1;

這會產生以下輸出 -

+----------+
| intvalue |
+----------+
|        1 |
+----------+
1 row in set (0.00 sec)

這是 intvalue=’1’ 的查詢 -

mysql> select * from DemoTable1566 where intvalue='1';

這會產生以下輸出 -

+----------+
| intvalue |
+----------+
|        1 |
+----------+
1 row in set (0.00 sec)

更新於: 12-12-2019

45 瀏覽

開啟你的 職業生涯

完成課程獲得認證

開始
廣告