Name
RTRIM
Synopsis
The RTRIM function is the opposite of RPAD and the companion to LTRIM. While RPAD adds characters to the right of a string, RTRIM removes, or trims, characters from the end portion of the string. Just as with RPAD, RTRIM offers much more flexibility than simply removing trailing blanks. The specification of the RTRIM function is:
FUNCTION RTRIM (string1IN VARCHAR2 [,trim_stringIN VARCHAR2]) RETURN VARCHAR2
RTRIM returns string1 with all trailing
characters removed up to the first character not found in the
trim_string. The second parameter is optional
and defaults to a single space.
Here are some examples of RTRIM:
Trim all trailing blanks from a string:
RTRIM ('Way Out in Right Field ') --> 'Way Out in Right Field'Because I did not specify a trim string, it defaults to a single space, so all trailing spaces are removed.
Trim all the characters in “BAM! ARGH!” from the end of a string:
my_string := 'Sound effects: BAM!ARGH!BAM!HAM'; RTRIM (my_string, 'BAM! ARGH!') --> 'Sound effects:'
This use of RTRIM strips off all the letters at the end of the string that are found in “BAM!ARGH!”. This includes “BAM” and “HAM”, so those words too are removed from the string even though “HAM” is not listed explicitly as a “word” in the trim string. Also, the inclusion of two exclamation marks in the trim string is unnecessary, because RTRIM is not looking for the word “ARGH!”, but for each of the letters in “ARGH!”.
Tip
The TRIM function implements ANSI-standard trim functionality. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access