如果 MySQL 的 VARCHAR 中儲存較長的字串,如何更可讀地顯示結果?


為此,請在以下語法中使用 \G −

select * from yourTableName\G

讓我們先建立一個表 −

mysql> create table DemoTable1482
   -> (
   -> Title varchar(255)
   -> );
Query OK, 0 rows affected (0.52 sec)

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

mysql> insert into DemoTable1482 values('Deep Dive using Java with Data Structure And Algorithm');
Query OK, 1 row affected (0.13 sec)
mysql> insert into DemoTable1482 values('Introduction To MySQL and MongoDB');
Query OK, 1 row affected (0.12 sec)

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

mysql> select * from DemoTable1482;

將生成以下輸出 −

+--------------------------------------------------------+
| Title                                                  |
+--------------------------------------------------------+
| Deep Dive using Java with Data Structure And Algorithm |
| Introduction To MySQL and MongoDB                      |
+--------------------------------------------------------+
2 rows in set (0.00 sec)

以下是使輸出更具可讀性的查詢 −

mysql> select * from DemoTable1482\G

將生成以下輸出 −

*************************** 1. row ***************************
Title: Deep Dive using Java with Data Structure And Algorithm
*************************** 2. row ***************************
Title: Introduction To MySQL and MongoDB
2 rows in set (0.00 sec)

更新時間: 2019 年 12 月 10 日

390 次瀏覽

開啟您的 職業生涯

透過完成課程獲得認證

開始
廣告
© . All rights reserved.