LPAD Function
The LPAD function returns a copy of source_string that is left-padded to the total number of characters specified by length.
Element | Description | Restrictions | Syntax |
---|---|---|---|
length | Integer value that specifies total number of characters in the returned string | Must be an expression, constant, column, or host variable of a data type that can be converted to an integer data type | Literal Number |
pad_string | String that specifies the pad character or characters | Must be an expression, constant, column, or host variable of a data type that can be converted to a character data type | Expression |
source_string | String that serves as input to the LPAD function | Must be an expression, constant, column, or host variable of a data type that can be converted to a character data type | Expression |
Any argument to the LPAD function must be of a built-in data type.
The pad_string parameter specifies the character or characters to be used for padding the source string. The sequence of pad characters occurs as many times as necessary to make the return string the storage length specified by length.
The series of pad characters in pad_string is truncated if it is too long to fit into length. If you specify no pad_string, the default value is a single blank (ASCII 32) character.
The return data type is based on the three arguments, using the return type promotion rules that the section Return Types from the CONCAT Function describes.
SELECT LPAD('Here we are', 16, '-_') FROM mytable;
(constant) |
---|
-_-_-Here we are |