RTRIM Function in Oracle SQL – PLSQL

The RTRIM Function in Oracle SQL / PLSQL is used to remove the specified characters in a string from the right side.

Syntax for the using the RTRIM Function in Oracle SQL / PLSQL is:

SELECT RTRIM(string_1,[string_2])
FROM table_name;

  • string_1 is the string which will be trimmed from the right side
  • string_2 is the string which will be matched in string_1 for trimming, it’s an optional parameter, if omitted then RTRIM function will remove all the spaces in string_1 from right side.

Examples:

Using RTRIM Function in Oracle SQL / PLSQL SELECT statement:

[sourcecode language=”sql”]
SELECT RTRIM(‘Tech Honey’, ‘y’)
FROM dual;
[/sourcecode]

Will return ‘Tech Hone’

[sourcecode language=”sql”]
SELECT RTRIM(‘Tech Honey’, ‘Honey’)
FROM dual;
[/sourcecode]

Will return ‘Tech’

[sourcecode language=”sql”]
SELECT RTRIM(‘Tech Honey ‘)
FROM dual;
[/sourcecode]

Will return ‘Tech Honey’

[sourcecode language=”sql”]
SELECT RTRIM(‘Tech Honey56789’, ‘0123456789’)
FROM dual;
[/sourcecode]

Will return ‘Tech Honey’

[sourcecode language=”sql”]
SELECT RTRIM(‘Tech Honey11111’, ‘1’)
FROM dual;
[/sourcecode]

Will return ‘Tech Honey’


Leave a Reply

Your email address will not be published. Required fields are marked *