dcsimg
 

Submitted by: M S Sridhar(sridhar.ms@gmail.com)

Tuesday Apr 28th 2020 by M S Sridhar

Language: SQL, Expertise: Intermediate: While the data is being fetched from the database, you may need to append space in some cases. MySQL provides the SPACE function that can help achieve this.

Programming has a multitude of requirements. While the data is being fetched from the database, you may need to append space in some cases. MySQL provides the SPACE function that can help achieve this.

Query:

SELECT CONCAT(COL1,SPACE(10)) FROM TABLE_NAME;

This will result in the values of all COL1 appended and returned.

Output:

+-------------------------+
| CONCAT(COL1,SPACE(10))  |
+-------------------------+
| VALUE1              |
+-------------------------+

And when you see the size of the column, it will be 6+10 = 16 in the above result set, the size of VALUE1 = 6 and size of SPACE(10) = 10. Sum of them is 6 + 10 = 16.

Home
Mobile Site | Full Site