MySQL SPACE() Function
In MySQL, the SPACE()
function returns a string consisting of a specified number of space characters.
SPACE()
Syntax
Here is the syntax of MySQL SPACE()
function:
SPACE(count)
Parameters
count
- Required. The number of space characters.
Return value
The SPACE()
function returns a string consisting of the specified number of spaces.
- If the parameter
count
is less than 1, theSPACE()
function returns an empty string''
. - if the parameter is
NULL
, theSPACE()
function will returnNULL
.
SPACE()
Examples
Here are some examples of MySQL SPACE()
function.
SELECT
LENGTH(SPACE(2)),
LENGTH(SPACE(6)),
LENGTH(SPACE(0)),
LENGTH(SPACE(-1)),
SPACE(NULL)\G
Note that we use the LENGTH()
function returns the length of the string for a more intuitive comparison result.
LENGTH(SPACE(2)): 2
LENGTH(SPACE(6)): 6
LENGTH(SPACE(0)): 0
LENGTH(SPACE(-1)): 0
SPACE(NULL): NULL