RTRIM
RTRIM(string)
Section titled “RTRIM(string)”- string: This parameter refers to the string of characters from which you want to remove extra whitespace on the right end.
Example
Section titled “Example”SELECT RTRIM('SQL ');Output
Section titled “Output”'SQL'Explanation
Section titled “Explanation”The RTRIM function in SQL is used to remove all the trailing whitespaces at the right-hand side of a given string. In the mentioned example, the function RTRIM has been applied to the string ‘SQL ’, which removes all the trailing spaces resulting in the output: ‘SQL’.
RTRIM( character_expression )
Section titled “RTRIM( character_expression )”- character_expression: A parameter that indicates the string from which SQL Server will remove trailing spaces. This expression can be of any data type that can be implicitly converted to varchar or nvarchar, otherwise, an error is returned. It cannot be a text or ntext data type.
Example
Section titled “Example”SELECT RTRIM('hello world ') AS TrimmedText;Output
Section titled “Output”'hello world'Explanation
Section titled “Explanation”The RTRIM function removed the trailing spaces from the right side of the input string.
RTRIM(character, trim_character)
Section titled “RTRIM(character, trim_character)”- character: The string from which trailing spaces or specified characters are to be trimmed. This must be a character literal, expression, or function.
- trim_character: The set of characters at the end of “character” that are to be trimmed. This must also be a character literal, expression, or function. If this parameter is omitted, Oracle will trim trailing spaces by default.
Example
Section titled “Example”SELECT RTRIM('Example ') AS TrimmedStringFROM dual;Output
Section titled “Output”TrimmedString-------------ExampleExplanation
Section titled “Explanation”In the given example, Oracle’s RTRIM function removes all the trailing spaces from the string ‘Example ’ and returns the trimmed string ‘Example’.
RTRIM(text, characters)
Section titled “RTRIM(text, characters)”- text: The string from which the trailing characters need to be removed.
- characters: The set of characters to be removed from the end of the string. If this parameter is omitted, spaces are removed by default.
Example
Section titled “Example”SELECT RTRIM('SQLite ');Output
Section titled “Output”'SQLite'Explanation
Section titled “Explanation”The RTRIM function in SQLite is used to remove all the trailing spaces from a string. In the given example, RTRIM function is applied to the string ‘SQLite ’, which has three trailing spaces at the end. The function removes these spaces and returns the string ‘SQLite’.