Open In App

SPACE() Function in MySQL

SPACE() function in MySQL is used to return a string consisting of specified empty space characters.

Syntax :



SPACE(num)

Parameter : This method accepts one parameter as mentioned above and described below :

Returns : It returns the string containing of specified number spaces .



Example-1 : SPACE() Function to return a string containing only spaces.

SELECT SPACE(6) AS String_Name;

Output :

String_Name

Example-2 : Applying SPACE() Function with CONCAT() Function return a string.

SELECT CONCAT('Geeks', SPACE(3), 'For', SPACE(3), 'Geeks') AS Company_Name;

Output :

Company_Name
Geeks For Geeks

Example-3 : Using SPACE() Function in a Table.

Table : Player_Details :

Player_Id First_Name Last_Name
101 Virat Kohli
102 Rohit Sharma
103 Sikhar Dhawan
SELECT CONCAT(First_Name, SPACE(3), Last_Name) AS Full_Name FROM Player_Details ;

Output :

Full_Name
Virat Kohli
Rohit Sharma
Sikhar Dhawan
Article Tags :
SQL