Skip to main content

SPACE

Description

Generate a string consisting of a specified number of spaces.

Syntax

SPACE ( <len> )

Parameters

ParameterDescription
<len>The number of spaces to generate

Return Value

Returns a string consisting of the specified number of spaces. Special cases:

  • If any Parameter is NULL, NULL will be returned.
  • When <len> is less than 0, an empty string is returned.

Examples

  1. Generate specified number of spaces
SELECT space(5);
+----------+
| space(5) |
+----------+
| |
+----------+
  1. Zero or negative number handling
SELECT space(0), space(-5);
+----------+-----------+
| space(0) | space(-5) |
+----------+-----------+
| | |
+----------+-----------+
  1. NULL value handling
SELECT space(NULL);
+-------------+
| space(NULL) |
+-------------+
| NULL |
+-------------+
  1. Use with other functions
SELECT CONCAT('Hello', space(3), 'World');
+------------------------------------+
| concat('Hello', space(3), 'World') |
+------------------------------------+
| Hello World |
+------------------------------------+

Keywords

SPACE