Open In App

PLSQL | RTRIM Function

Last Updated : 04 Feb, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

The PLSQL RTRIM function is used for removing all specified characters from the right-hand side of a string. The PLSQL RTRIM function accepts two parameters which are input_string and trim_string. 

  • If the user does not specify trim_string, it defaults to a single blank. 
  • If char is a character literal, then you must enclose it in single quotes. 

Oracle Database begins scanning char from its first character and removes all characters that appear in trim_string until reaching a character not in trim_string and then returns the result. 

Syntax:  

RTRIM( input_string [, trim_string] )

Parameters Used:  

  1. input_string – It is used to specify the string whose characters need to be trimmed from the right hand side.
  2. trim_string – It is an optional parameter which is used to specify the string that will be removed from the right-hand side of input_string. If this parameter is omitted, the RTRIM function removes all leading spaces from input_string. 

Supported Versions of Oracle/PLSQL:  

  1. Oracle 12c
  2. Oracle 11g
  3. Oracle 10g
  4. Oracle 9i
  5. Oracle 8i

Example-1:  

DECLARE 
   Test_String string(25) := 'Geeksforgeeks    ';
   
BEGIN 
   dbms_output.put_line(RTRIM(Test_String)); 
   
END;   

Output:  

Geeksforgeeks 

Example-2:  

DECLARE 
   Test_String string(25) := 'Geeksforgeeks      ';
   
BEGIN 
   dbms_output.put_line(RTRIM(Test_String, ' ')); 
   
END;   

Output:  

Geeksforgeeks 

Example-3:  

DECLARE 
   Test_String string(25) := 'Geeksforgeeks123';
   
BEGIN 
   dbms_output.put_line(RTRIM(Test_String, '123')); 
   
END; 

Output:  

Geeksforgeeks 

Example-4:  

DECLARE 
   Test_String string(25) := 'Geeksforgeeks123123';
   
BEGIN 
   dbms_output.put_line(RTRIM(Test_String, '123')); 
   
END;   

Output:  

Geeksforgeeks 

Example-5:  

DECLARE 
   Test_String string(25) := 'Geeks123forgeeks123';
   
BEGIN 
   dbms_output.put_line(RTRIM(Test_String, '123')); 
   
END;    

Output:  

Geeks123forgeeks 

 


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads