SPACE
SPACE is a SQL function that is used to return a string of spaces whose length is equal to the provided numerical value. It primarily operates to generate a specific number of space characters for formatting and structuring SQL queries and their outputs.
SPACE(N)
- 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.
Example
Output
Explanation
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.
SPACE( integer_expression )
- integer_expression: This parameter determines the number of spaces to be returned by the SQL Server SPACE function. It should be an integer. If a negative number or a value larger than 255 is specified, NULL is returned.
Example
Output
Explanation
In the given code example, the SPACE
function in SQL is used to insert five spaces before the string ‘SQL’. The result is thus the string ‘SQL’ preceded by five spaces.
SPACE(n)
- n: Integer value that specifies the number of spaces to be returned. The SPACE function will output a string consisting of ‘n’ number of space characters.
Example
Output
Explanation
The SPACE
function in Oracle SQL creates a string of specified length filled with spaces. In this example, SPACE(10)
creates a 10-character string filled with spaces. It’s followed by the string ‘Hello’, resulting in ‘Hello’ preceded by 10 spaces.
SPACE(n)
- n: This parameter specifies the number of space characters to be returned by the function. Its value can be any positive integer.
Example
Output
Explanation
The SPACE function in SQL is used to generate a string of spaces. In this example, SPACE(5) returns a string with 5 spaces. The LENGTH function then calculates the number of characters in this string, which is 5. This means that 5 spaces were created.