我們是否可以在MySQL中的列值中使用反引號?


您不能在列值中使用反引號。只對此使用表名或列名即可。如果您在列值中使用反引號,MySQL 將給以下錯誤資訊

ERROR 1054 (42S22): Unknown column '191.23.41.10' in 'where clause'

讓我們先建立一張表

mysql> create table DemoTable6
(
   SystemIPAddress varchar(200)
);
Query OK, 0 rows affected (0.46 sec)

以下是使用 insert 命令在表中插入一些記錄的查詢

mysql> insert into DemoTable values('192.68.1.0');
Query OK, 1 row affected (0.19 sec)
mysql> insert into DemoTable values('191.23.41.10');
Query OK, 1 row affected (0.12 sec)

現在您可以使用 select 語句從表中顯示特定記錄

mysql> select *from DemoTable where SystemIPAddress=`191.23.41.10`;

這將產生以下輸出,即錯誤,因為我們在列值中使用了反引號

ERROR 1054 (42S22): Unknown column '191.23.41.10' in 'where clause'

讓我們看看顯示同一記錄的正確方式

mysql> select *from DemoTable where SystemIPAddress='191.23.41.10';

這將產生以下輸出

+-----------------+
| SystemIPAddress |
+-----------------+
| 191.23.41.10    |
+-----------------+
1 row in set (0.00 sec)

更新於: 30-Jul-2019

189 次瀏覽

開啟你的 職業生涯

完成課程,獲得認證

開始學習
廣告