MySQL Space Function

The MySQL SPACE is one of the String functions, which returns a string consisting of specified empty space characters. The syntax behind this SPACE is as shown below:


MySQL SPACE Function Example

The String Space function simply returns whitespace charters for N number of times. The following query shows the use of this function.

From the below MySQL screenshot, the first statement is returning whitespaces.

Well, you may not notice that whitespace. So, let me concat two strings along with the function in the second statement.


SELECT CONCAT('Tutorial', SPACE(5), 'Gateway') AS Website;

Example 1

The String Space is also helpful for you to combine (concat) multiple columns. In this example, we will use this function to combine the FirstName and LastName columns. For this, We are going to use the below-shown data

Employee table 2

and the String Function code is:

       CONCAT(FirstName, SPACE(6), LastName) AS FullName,
  FROM `mysql tutorial`.employee;
MySQL Space Function 3

TIP: We used 6 as. the argument value to get Six empty whitespaces between First Name and Last name.

About Suresh

Suresh is the founder of TutorialGateway and a freelance software developer. He specialized in Designing and Developing Windows and Web applications. The experience he gained in Programming and BI integration, and reporting tools translates into this blog. You can find him on Facebook or Twitter.