Remove Spaces/Characters from Right in Oracle

Remove Spaces/Characters from Right in Oracle

  • SQL
  • 1 min read

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: