Oracle RPAD() Function
Oracle RPAD() is a built-in function that pads a given string with a given character sequence on the right side to reach a specified length.
If you need to left-pad a string, use LPAD().
Oracle RPAD() Syntax
Here is the syntax for the Oracle RPAD() function:
RPAD(str, len [, padstr ])
Parameters
str-
Required. The string to be padded. It can be of type
CHAR,VARCHAR2,NCHAR,NVARCHAR2,CLOB, orNCLOB. len-
Required. The length the padded string needs to reach. It must be a
NUMBERinteger or a value that can be implicitly converted to aNUMBERinteger. padstr-
Optional. The string to be padded to the right of the original string. The default value is a space.
Return Value
The Oracle RPAD() function returns a string that is padded to the right of the original string with the given character sequence to the specified length.
The return value of RPAD() has the same data type and character set as the str parameter.
If len is less than the length of the original string str, RPAD() returns a portion of the string that is len characters long.
If any of the parameters are NULL, RPAD() returns NULL.
Oracle RPAD() Examples
Here are some examples that demonstrate the usage of the Oracle RPAD() function.
Basic Usage
SELECT
RPAD('Hello', 10) Result1,
RPAD('Hello', 10, '_') Result2
FROM dual;
Output:
RESULT1 RESULT2
_____________ _____________
Hello Hello_____Padding with a Character Sequence
The Oracle RPAD() function allows you to pad a string with a specified character sequence:
SELECT
RPAD('Hello', 10, 'xyz') Result
FROM dual;
Output:
RESULT
_____________
HelloxyzxyNULL Parameters
If any of the parameters are NULL, the function returns NULL.
SET NULL 'NULL';
SELECT
RPAD(NULL, 10) Result1,
RPAD('A', NULL) Result2,
RPAD('A', 10, NULL) Result3,
RPAD(NULL, NULL, NULL) Result4
FROM dual;
Output:
RESULT1 RESULT2 RESULT3 RESULT4
__________ __________ __________ __________
NULL NULL NULL NULLIn this example, we use the statement SET NULL 'NULL'; to display NULL values as the string 'NULL'.
Conclusion
Oracle RPAD() is a built-in function that pads a given string with a given character sequence on the right side to reach a specified length.