Purpose
The LPAD function pads the left side of the string char1 with the string char2 until the length reaches n.
Note
- If the length of
char1is greater thann, the function returns the leftmostncharacters ofchar1. - If the length of
char1is less thann, and the concatenation ofchar2andchar1exceedsn, the function returns the rightmostncharacters of the concatenated result.
Syntax
LPAD(char1,n[,char2])
Parameters
Parameter |
Description |
|---|---|
| char1 | The string to be padded. The string type can be CHAR, VARCHAR2, NCHAR, NVARCHAR2, or CLOB. |
| n | The total length after padding. 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 be used for padding. The default is a space. The string type can be CHAR, VARCHAR2, NCHAR, NVARCHAR2, or CLOB. |
Return type
If
char1is a character data type, the function returns aVARCHAR2value.If
char1is a national character data type, the function returns anNVARCHAR2value.If
char1is aLOBdata type, the function returns aLOBvalue.
Examples
Use the star * to left-pad the string ABCDE.
obclient> SELECT LPAD('ABCDE',10,'*') FROM DUAL;
+----------------------+
| LPAD('ABCDE',10,'*') |
+----------------------+
| *****ABCDE |
+----------------------+
1 row in set
