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 (string1 IN VARCHAR2 [, trim_string IN 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. ...

Get Oracle PL/SQL Programming, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.