Skip to main content

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​

ParameterDescription
<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​

  1. Remove trailing spaces
SELECT rtrim_in('ab d   ') str;
+------+
| str |
+------+
| ab d |
+------+
  1. Remove specified character set
-- RTRIM_IN removes any 'a' and 'b' characters from the right end
SELECT rtrim_in('ababccaab', 'ab') str;
+---------+
| str |
+---------+
| ababcc |
+---------+
  1. Comparison with RTRIM function
SELECT rtrim_in('ababccaab', 'ab'),rtrim('ababccaab', 'ab');
+-----------------------------+--------------------------+
| rtrim_in('ababccaab', 'ab') | rtrim('ababccaab', 'ab') |
+-----------------------------+--------------------------+
| ababcc | ababcca |
+-----------------------------+--------------------------+