How to display the result more readable if the string is long stored in MySQL VARCHAR?

MySQLMySQLi Database

For this, use \G as in the below syntax −

select * from yourTableName\G

Let us first create a table −

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

Insert some records in the table using insert command −

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)

Display all records from the table using select statement −

mysql> select * from DemoTable1482;

This will produce the following output −

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

Following is the query to make the output more readable −

mysql> select * from DemoTable1482\G

This will produce the following output −

*************************** 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)
raja
Published on 10-Dec-2019 08:07:34
Advertisements