Purpose
LPAD() left-pads char1 with char2 to n characters in length.
Note
- If
char1is longer thanncharacters, the function returns the leftmostncharacters ofchar1. - If
char1is shorter thanncharacters, and the combined length ofchar1andchar2is greater thanncharacters, the function returns the rightmostncharacters of the padded string.
Syntax
LPAD(char1,n[,char2])
Parameters
| Parameter | Description |
|---|---|
| char1 | The source string. 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 the NUMBER data type or any data type that can be implicitly converted to the 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
char1is of the character data type, the return type isVARCHAR2.If
char1is of the national character data type, the return type isNVARCHAR2.If
char1is of theLOBdata type, the return type isLOB.
Examples
The following example left-pads the string ABCDE with asterisks (*).
obclient> SELECT LPAD('ABCDE',10,'*') FROM DUAL;
+----------------------+
| LPAD('ABCDE',10,'*') |
+----------------------+
| *****ABCDE |
+----------------------+
1 row in set