<<<<<<< HEAD space | H2 | SQLDoc
Skip to main content

space

1. SPACE Function

======= space | H2 Function | SQLDoc

space

1. SPACE Function

>>>>>>> 9d19b1c8cb744c8e86d5c15b74d8b5f719ad62be

The SPACE function in H2 database is used to generate a string consisting of a specified number of spaces.

2. Syntax

The syntax for the SPACE function in H2 database is as follows:

SPACE(length)

Arguments

  • length: The number of spaces to be included in the generated string. It should be a non-negative integer value.

Return

  • The SPACE function returns a string containing the specified number of spaces.

3. Notes

  • The SPACE function in H2 database does not accept non-integer values for the length parameter. If a non-integer value is provided, it will be rounded down to the nearest integer.
  • If the length parameter is negative, the SPACE function will return an empty string.
  • The maximum length that can be specified for the SPACE function is the maximum value of the INTEGER data type in H2 database, which is 2,147,483,647.

4. Examples

Here are a few examples demonstrating the usage of the SPACE function in H2 database:

Example 1 - Generating a string of 5 spaces:

SELECT SPACE(5) AS spaces;

Output:

spaces
------

Example 2 - Combining the SPACE function with other string functions:

SELECT CONCAT('Hello', SPACE(3), 'World') AS result;

Output:

result
-------------
Hello World

Example 3 - Using the SPACE function in a query:

SELECT id, CONCAT(name, SPACE(10 - LENGTH(name)), age) AS info
FROM users;

Output:

id | info
---+----------------
1 | John 25
2 | Emma 33
3 | Michael 41

There are no specific related functions for the SPACE function in H2 database. However, you can combine it with other string functions like CONCAT or TRIM to achieve desired results.