How to see spaces in data when selecting with MySQL command line client?


Use quote() function for this. The syntax is as follows −

select yourColumnName,quote(yourColumnName) from yourTableName;

To understand the concept, let us create a table. The query to create a table is as follows −

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

Insert some records in the table using insert command. The query is as follows −

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)

Display all records from the table using select statement. The query is as follows −

mysql> select *from seeSpacesDemo;

The following is the output −

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

Here is the query to see spaces in data when selecting with MySQL command line client −

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

The following is the output −

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

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 30-Jul-2019

140 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements