LPAD

2023-12-25 08:49:42  Updated

Purpose

LPAD() left-pads 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 rightmost n characters of the padded string.

Syntax

LPAD(char1,n[,char2])

Parameters

Parameter Description
char1 The string from which the characters are to be removed. 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 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 left-pads the string ABCDE with asterisks (*).

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

Contact Us