RTRIM() function removes all characters that appear in a specified set from the right end of a string.
The following illustrates the syntax of the Oracle
RTRIM() function accepts two arguments:
is the string which the characters that appear in the set will be removed.
is one or more characters that should be removed from the right end of the
set argument is optional. If you omit it when calling the
RTRIM() function, it will default to a single space. In other words, the
RTRIM() function will remove the spaces from the right end of the trim_source by default.
The data types of both
set can be one of the following data types: CHAR, VARCHAR2, NCHAR, NVARCHAR2, CLOB, or NCLOB.
RTRIM() function returns a string with all characters that appear in the set removed from the right end of the string.
The data type of the result returned string is VARCHAR2 if
source_string is a character value or LOB if
source_string is a LOB value.
The following statement removes all spaces at the right end of a string
SELECT RTRIM( 'ABC ' ) FROM dual;
Here is the result:
As you can see, two spaces at the end of the string were removed.
See the following example:
SELECT RTRIM( 'ABC12345543', '345' ) FROM dual;
The result is:
For every character in the set
RTRIM() function removed the right-most occurrences of each from the string.
Let’s see the
products table in the sample database:
The following statement returns products whose names end with
SELECT product_name FROM products WHERE product_name LIKE '%V_' ORDER BY product_name;
You can use the
RTRIM() function to remove the version e.g., V1, V2, etc., from the product names as follows:
SELECT product_name, RTRIM(product_name,'V12345679') short_name FROM products WHERE product_name LIKE '%V_' ORDER BY product_name;
In this tutorial, you have learned how to use the Oracle
RTRIM() function to remove unwanted characters from the right end of a string.