Name

SPACE()

Synopsis

SPACE(count)

This function returns a string of spaces. The number of spaces returned is set by the argument. Here is an example:

SELECT CONCAT(name_first, SPACE(1), name_last)
AS Name
FROM students LIMIT 1;

+------------------+
| Name             |
+------------------+
| Richard Stringer |
+------------------+

Although this example requires a lot more typing than just placing a space within quotes, it’s more apparent when glancing at it that a space is to be inserted. For multiple or variable spaces, you could substitute the count with another function to determine the number of spaces needed based on data from a table, the length of other inputs, or some other factor.

Get MySQL in a Nutshell, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.