Oracle / PLSQL: RTRIM Function

This article is written about how to use the Oracle/PLSQL RTRIM characteristic with syntax and examples.

Description

The Oracle/PLSQL RTRIM feature eliminates all distinct characters from the right-hand facet of a string.

Syntax

The syntax for the RTRIM function in Oracle/PLSQL is:

RTRIM( string1 [, trim_string ] )

Parameters or Arguments

string1 The string to trim the characters from the right-hand side. trim_string Optional. The string that will be removed from the right-hand side of string1. If this parameter is omitted, the RTRIM function will remove all trailing areas from string1.

Returns

The RTRIM function returns a string value.

Note

See also the LTRIM and TRIM functions.

Applies To

The RTRIM feature can be used in the following versions of Oracle/PLSQL:

Oracle 12c, Oracle 11g, Oracle 10g, Oracle 9i, Oracle 8i

Example

Let’s seem to be at some Oracle RTRIM feature examples and discover how to use the RTRIM function in Oracle/PLSQL.

For example:

RTRIM('tech   ')
Result: 'tech'

RTRIM('tech   ', ' ')
Result: 'tech'

RTRIM('123000', '0')
Result: '123'

RTRIM('Tech123123', '123')
Result: 'Tech'

RTRIM('123Tech123', '123')
Result: '123Tech'

RTRIM('Techxyxzyyy', 'xyz')
Result: 'Tech'

RTRIM('Tech6372', '0123456789')
Result: 'Tech'

The RTRIM characteristic may also appear to get rid of patterns, however this is no longer the case as established in the following example.

RTRIM('Techxyxxyzyyyxx', 'xyz')
Result: 'Tech'

It honestly eliminates the man or woman occurrences of ‘x’, ‘y’, and ‘z’, as hostile to the pattern of ‘xyz’.

The RTRIM characteristic can also be used to put off all trailing numbers as demonstrated in the next example.

RTRIM('Tech6372', '0123456789')
Result: 'Tech'

In this example, every variety aggregate from 0 to 9 has been listed in the trim_string parameter. By doing this, it does not matter the order that the numbers show up in string1, all trailing numbers will be removed by means of the RTRIM function.