dcsimg
LinkedIn
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: SQL
Expertise: Intermediate
Apr 28, 2020

Understanding the SPACE Function in MySQL

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.

M S Sridhar
 
Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date