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)