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

ltrim

1. LTRIM Function

======= ltrim | H2 Function | SQLDoc

ltrim

1. LTRIM Function

>>>>>>> 9d19b1c8cb744c8e86d5c15b74d8b5f719ad62be

The LTRIM function in H2 database is used to remove leading spaces (or specified characters) from a string.

2. Syntax

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

LTRIM(string [, characters])

Arguments

  • string: The string from which leading spaces (or characters) need to be removed.
  • characters (optional): The specific characters to remove from the beginning of the string. If not provided, it will remove leading spaces by default.

Return

  • The LTRIM function returns the modified string with leading spaces or specified characters removed.

3. Notes

  • The LTRIM function in H2 database only removes leading spaces or specified characters from the beginning of the string. It does not remove trailing spaces or characters.
  • If the input string is NULL, the LTRIM function will return NULL.
  • The characters argument is optional. If provided, the LTRIM function will remove the specified characters from the beginning of the string.

4. Examples

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

Example 1 - Removing leading spaces from a string:

SELECT LTRIM('   Hello, World!') AS result;

Output:

result
----------
Hello, World!

Example 2 - Removing specific characters from the beginning of a string:

SELECT LTRIM('---Hello, World!---', '-') AS result;

Output:

result
----------
Hello, World!---

Example 3 - Removing leading spaces from a column:

CREATE TABLE names (
id INT PRIMARY KEY,
name VARCHAR(100)
);

INSERT INTO names VALUES (1, ' John'), (2, ' Alice'), (3, 'Bob ');

SELECT id, LTRIM(name) AS trimmed_name
FROM names;

Output:

id | trimmed_name
---+-------------
1 | John
2 | Alice
3 | Bob
  • rtrim - Remove trailing spaces or specified characters from a string.
  • trim - Remove leading and trailing spaces or specified characters from a string.