in

Remove Spaces/Characters from Right in Oracle

In Oracle, use the rtrim() function to remove spaces or specific characters from the right side in a string.

RTRIM() Function Syntax

rtrim(char, set)

RTRIM eliminates all occurrences of the set from the rightmost portion of char. For more readable query results, use this function.

Removing Spaces from the Right Side in a String in Oracle Example

The following SQL query removes the spaces from the string:

select rtrim('Oracle ', ' ') from dual;

Output:

Oracle

Removing Comma from the Right Side in a String in Oracle

Below SQL query removes the comma ',' from the right side of the string:

select rtrim('Oracle,', ',') from dual;

Using RTRIM() Function in PL/SQL

declare
v_string varchar2(100);
begin
v_string := rtrim('Oracle,,,,', ',');
dbms_output.put_line(v_string);
end;

Output:

Oracle

See also:

Written by Rony Dsouza

Rony is an Oracle programmer, having more than 15 years of experience. He likes to write on SQL, PL/SQL, and Oracle Apex topics. Also, expertise in Python, PHP, MySQL, JavaScript, etc.

Leave a Reply

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