PLSQL | RPAD Function - GeeksforGeeks

25 Sep, 2019
The PLSQL RPAD function is used for padding the right-side of a string with a specific set of characters. a prerequisite for this is that string shouldn’t be NULL. The RPAD function in PLSQL is useful for formatting the output of a query. The RPAD function accepts three parameters which are input_string, padded_length and the pad_string.
Both input_string and pad_string can be any of the datatypes CHAR, VARCHAR2, NCHAR, NVARCHAR2, CLOB, or NCLOB. The string returned is of VARCHAR2 datatype if input_string is a character datatype.
The argument padded_length must be a NUMBER integer or a value that can be implicitly converted to a NUMBER integer.
If you do not specify pad_string, then the default is a single blank. If input_string is longer than padded_length, then this function returns the portion of input_string that fits in padded_length.
Syntax:
RPAD( input_string, padded_length, pad_string)
Parameters Used:
input_string – It is used to specify the string which needs to be formatted.string_to_replace – It is used to specify the number of characters to return. If the padded_length is smaller than the original string, the RPAD function will truncate the string to the size of padded_length.pad_string – It is an optional parameter which is used to specify the input_string that will be padded to the right-hand side of string. If this parameter is omitted, the RPAD function will pad spaces to the right-side of the input_string.
input_string – It is used to specify the string which needs to be formatted.
string_to_replace – It is used to specify the number of characters to return. If the padded_length is smaller than the original string, the RPAD function will truncate the string to the size of padded_length.
pad_string – It is an optional parameter which is used to specify the input_string that will be padded to the right-hand side of string. If this parameter is omitted, the RPAD function will pad spaces to the right-side of the input_string.
Supported Versions of Oracle/PLSQL:
Oracle 12cOracle 11gOracle 10gOracle 9iOracle 8i
Oracle 12c
Oracle 11g
Oracle 10g
Oracle 9i
Oracle 8i
Example-1:
DECLARE 
   Test_String string(20) := 'Geeksforgeeks';
   
BEGIN 
   dbms_output.put_line(RPAD(Test_String, '5')); 
   
END;     
Output:
Geeks 
Example-2:
DECLARE 
   Test_String string(20) := 'Geeksforgeeks';
   
BEGIN 
   dbms_output.put_line(RPAD(Test_String, '17')); 
   
END;    
Output:
Geeksforgeeks  
Example-3:
DECLARE 
   Test_String string(20) := 'Geeksforgeeks';
   
BEGIN 
   dbms_output.put_line(RPAD(Test_String, '17', '0')); 
   
END;  
Output:
Geeksforgeeks0000 
Example-4:
DECLARE 
   Test_String string(20) := 'Geeksforgeeks';
   
BEGIN 
   dbms_output.put_line(RPAD(Test_String, '5')); 
   
END;     
Output:
Geeksforgeek 
SQL-PL/SQL
SQL
SQL
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
How to Update Multiple Columns in Single Update Statement in SQL?
SQL | Subquery
How to Create a Table With Multiple Foreign Keys in SQL?
What is Temporary Table in SQL?
SQL Query to Find the Name of a Person Whose Name Starts with Specific Letter
SQL Query to Convert VARCHAR to INT
SQL using Python
How to Write a SQL Query For a Specific Date Range and Date Time?
How to Select Data Between Two Dates and Times in SQL Server?
SQL Query to Compare Two Dates