right
1. RIGHT Function
=======right
1. RIGHT Function
>>>>>>> 9d19b1c8cb744c8e86d5c15b74d8b5f719ad62beThe RIGHT function in H2 database is used to extract a specified number of characters from the right end of a given string.
2. Syntax
The syntax for the RIGHT function in H2 database is as follows:
RIGHT(string, length)
Arguments
string
: The input string from which characters need to be extracted.length
: The number of characters to be extracted from the right end of the string.
Return
- The RIGHT function returns a substring containing the specified number of characters from the right end of the input string.
3. Notes
- The RIGHT function is case-sensitive. It extracts characters from the right end of the string as it is, without considering the case.
- If the length is negative, the RIGHT function returns an empty string.
- If the input string is
NULL
, the RIGHT function will also returnNULL
.
4. Examples
Here are a few examples demonstrating the usage of the RIGHT function in H2 database:
Example 1 - Extracting the rightmost 3 characters from a string:
SELECT RIGHT('Hello World', 3) AS result;
Output:
result
------
rld
Example 2 - Extracting a specified number of characters from a column:
CREATE TABLE names (
id INT PRIMARY KEY,
name VARCHAR(50)
);
INSERT INTO names VALUES (1, 'John Doe'), (2, 'Jane Smith'), (3, 'Michael Johnson');
SELECT id, name, RIGHT(name, 5) AS result
FROM names;
Output:
id | name | result
---+-----------------+--------
1 | John Doe | Doe
2 | Jane Smith | Smith
3 | Michael Johnson | hnson