RTRIM_IN
Descriptionβ
The RTRIM_IN function removes specified characters from the right side of a string. When no character set is specified, it removes trailing spaces by default. When a character set is specified, it removes all specified characters from the right side (regardless of their order in the set). The key feature of RTRIM_IN is that it removes any combination of characters from the specified set, while the RTRIM function removes characters based on exact string matching.
Syntaxβ
RTRIM_IN(<str>[, <rhs>])
Parametersβ
Parameter | Description |
---|---|
<str> | The string to be processed. Type: VARCHAR |
<rhs> | Optional parameter, the set of characters to be removed. Type: VARCHAR |
Return Valueβ
Returns VARCHAR type, representing the processed string.
Special cases:
- If str is NULL, returns NULL
- If rhs is not specified, removes all trailing spaces
- If rhs is specified, removes all characters from the right side that appear in rhs until encountering the first character not in rhs
Examplesβ
- Remove trailing spaces
SELECT rtrim_in('ab d ') str;
+------+
| str |
+------+
| ab d |
+------+
- Remove specified character set
-- RTRIM_IN removes any 'a' and 'b' characters from the right end
SELECT rtrim_in('ababccaab', 'ab') str;
+---------+
| str |
+---------+
| ababcc |
+---------+
- Comparison with RTRIM function
SELECT rtrim_in('ababccaab', 'ab'),rtrim('ababccaab', 'ab');
+-----------------------------+--------------------------+
| rtrim_in('ababccaab', 'ab') | rtrim('ababccaab', 'ab') |
+-----------------------------+--------------------------+
| ababcc | ababcca |
+-----------------------------+--------------------------+