如果 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.