Skip to content

SPACE

  • n: The number of spaces to be returned by the “SPACE(N)” function. It is a required parameter where N represents an integer value indicating the count of spaces. The function then returns a string that consists of N number of spaces. It is important to know that N must be a positive integer, otherwise, the function will return an error.
SELECT CONCAT('Hello', SPACE(5), 'World') AS SpacedString;
+-----------------+
| SpacedString |
+-----------------+
| Hello World |
+-----------------+

The example showcases the usage of the SPACE() function in MySQL. This function takes an integer as an argument and generates a string of spaces equal to the integer value. In this case, SPACE(5) generates a string of 5 spaces. CONCAT() function is used to join ‘Hello’, 5 spaces, and ‘World’ into a single string. As a result, it returns a string with ‘Hello’ and ‘World’ separated by 5 spaces.