RPAD

2023-10-24 09:23:03  Updated

Purpose

You can call this function to right-pad char1 with char2 to n characters in length.

Note

  • If char1 is longer than n characters, the function returns the leftmost n characters of char1.
  • If char1 is shorter than n characters, and the combined length of char1 and char2 is greater than n characters, the function returns the leftmost n characters of the padded string.
  • If char1 is shorter than n characters, and the combined length of char1 and char2 is smaller than n characters, the function returns the leftmost n characters of a string obtained by padding char1 with char2 replicated for multiple times, where the total length of the string is greater than or equal to n characters.

Syntax

RPAD(char1, n[, char2])

Parameters

Parameter Description
char1 The string to be padded. It can be of the CHAR, VARCHAR2, NCHAR, NVARCHAR2, or CLOB data type.
n The total length of the returned string after padding. It must be of a NUMBER data type or any data type that can be implicitly converted to a NUMBER data type.
Note
A non-integer value is rounded down to an integer.
char2 The string to be padded with. The default value is a blank space. It can be of the CHAR, VARCHAR2, NCHAR, NVARCHAR2, or CLOB data type.

Return type

  • If char1 is of the character data type, the return type is VARCHAR2.

  • If char1 is of the national character data type, the return type is NVARCHAR2.

  • If char1 is of the LOB data type, the return type is LOB.

Examples

The following example right-pads the string ABCDE with asterisks (*) to 10 characters in length.

obclient> SELECT  RPAD('ABCDE',10,'*') "RPAD" FROM DUAL;
+------------+
 RPAD       
+------------+
 ABCDE***** 
+------------+
1 row in set

Contact Us