使用 MySQL 命令列客戶端用於選擇時如何檢視資料中的空格?


請為此使用 quote() 函式。語法如下 −

select yourColumnName,quote(yourColumnName) from yourTableName;

為了理解這個概念,讓我們建立一個表。建立表的查詢如下 −

mysql> create table seeSpacesDemo
   -> (
   -> spaceValue varchar(10)
   -> );
Query OK, 0 rows affected (0.42 sec)

使用 insert 命令在表中插入一些記錄。查詢如下 −

mysql> insert into seeSpacesDemo values("");
Query OK, 1 row affected (0.70 sec)
mysql> insert into seeSpacesDemo values(" ");
Query OK, 1 row affected (0.45 sec)
mysql> insert into seeSpacesDemo values(" ");
Query OK, 1 row affected (0.21 sec)
mysql> insert into seeSpacesDemo values(" ");
Query OK, 1 row affected (0.16 sec)

使用 select 語句從表中顯示所有記錄。查詢如下 −

mysql> select *from seeSpacesDemo;

以下是輸出 −

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

以下是使用 MySQL 命令列客戶端進行選擇時檢視資料中空格的查詢 −

mysql> select spaceValue,quote(spaceValue) from seeSpacesDemo;

以下是輸出 −

+------------+-------------------+
| spaceValue | quote(spaceValue) |
+------------+-------------------+
|            | ''                |
|            | ' '               |
|            | ' '               |
|            | ' '               |
+------------+-------------------+
4 rows in set (0.00 sec)

更新時間:2019 年 7 月 30 日

159 次檢視

啟動您的 職業

透過完成課程獲得認證

開始
廣告