Purpose
This function fills the right side of the string char1 with the string char2 until the total length reaches n.
Note
- If the length of
char1is greater thann, it returns the leftmostncharacters ofchar1. - If the length of
char1is less thann, and the combined length ofchar1andchar2is greater thann, it returns the leftmostncharacters of the combined string. - If the length of
char1is less thann, and the combined length ofchar1andchar2is less thann, it returns the leftmostncharacters of the string formed by concatenatingchar1with multiple copies ofchar2(total length is greater than or equal ton).
Syntax
RPAD(char1,n[,char2])
Parameters
Parameter |
Description |
|---|---|
| char1 | The string. The string type can be CHAR, VARCHAR2, NCHAR, NVARCHAR2, or CLOB. |
| n | The total length after appending. It must be a NUMBER type or a value that can be implicitly converted to NUMBER. Note For non-integer values, the decimal part is truncated to convert to an integer. |
| char2 | The string to append. The default value is a space. The string type can be CHAR, VARCHAR2, NCHAR, NVARCHAR2, or CLOB. |
Return type
If
char1is a character data type, it returns aVARCHAR2type.If
char1is a national character data type, it returns anNVARCHAR2type.If
char1is aLOBdata type, it returns aLOBtype.
Examples
Use the asterisk * to right-fill the string ABCDE to a length of 10 characters.
obclient> SELECT RPAD('ABCDE',10,'*') "RPAD" FROM DUAL;
+------------+
| RPAD |
+------------+
| ABCDE***** |
+------------+
1 row in set
