btrim
1. BTRIM Function
=======btrim
1. BTRIM Function
>>>>>>> 9d19b1c8cb744c8e86d5c15b74d8b5f719ad62beThe BTRIM function in H2 database is used to remove specified characters from the beginning and/or end of a string.
2. Syntax
The syntax for the BTRIM function in H2 database is as follows:
BTRIM(string, characters)
Arguments
string
: The input string from which characters need to be trimmed.characters
: (Optional) The characters to be removed from the beginning and/or end of the string. If not specified, it will remove whitespace characters.
Return
- The BTRIM function returns a new string with the specified characters removed from the beginning and/or end.
3. Notes
- The BTRIM function in H2 database trims characters from both the beginning and the end of the string. It does not trim characters from the middle of the string.
- If the input string is
NULL
, the BTRIM function will returnNULL
. - When the
characters
argument is not provided, the BTRIM function removes leading and trailing whitespace characters. - The
characters
argument can be a single character or multiple characters. It can also be a string literal or a column value.
4. Examples
Here are a few examples demonstrating the usage of the BTRIM function in H2 database:
Example 1 - Trimming whitespace characters:
SELECT BTRIM(' Hello, World! ') AS trimmed_string;
Output:
trimmed_string
---------------
Hello, World!
Example 2 - Trimming specific characters:
SELECT BTRIM('...Hello, World!...', '.') AS trimmed_string;
Output:
trimmed_string
---------------
Hello, World!
Example 3 - Trimming characters using a column value:
CREATE TABLE messages (
id INT PRIMARY KEY,
message VARCHAR(100)
);
INSERT INTO messages VALUES (1, '!!!Important Message!!!'), (2, ' Hello, H2! ');
SELECT id, message, BTRIM(message, '! ') AS trimmed_message
FROM messages;
Output:
id | message | trimmed_message
---+-------------------------+----------------
1 | !!!Important Message!!! | Important Message
2 | Hello, H2! | Hello, H2!