FirebirdSQL logo

LPAD()

Left-pads a string

Result type

VARCHAR or BLOB

Syntax
LPAD (str, endlen [, padstr])
Table 1. LPAD Function Parameters
Parameter Description

str

An expression of a string type

endlen

Output string length

padstr

The character or string to be used to pad the source string up to the specified length.Default is space (“' '”)

Left-pads a string with spaces or with a user-supplied string until a given length is reached.

  • This function fully supports text BLOBs of any length and character set.

  • If str is a BLOB, the result is a BLOB.Otherwise, the result is a VARCHAR(endlen).

  • If padstr is given and equal to '' (empty string), no padding takes place.

  • If endlen is less than the current string length, the string is truncated to endlen, even if padstr is the empty string.

Warning

When used on a BLOB, this function may need to load the entire object into memory.Although it does try to limit memory consumption, this may affect performance if huge BLOBs are involved.

LPAD Examples

lpad ('Hello', 12)               -- returns '       Hello'
lpad ('Hello', 12, '-')          -- returns '-------Hello'
lpad ('Hello', 12, '')           -- returns 'Hello'
lpad ('Hello', 12, 'abc')        -- returns 'abcabcaHello'
lpad ('Hello', 12, 'abcdefghij') -- returns 'abcdefgHello'
lpad ('Hello', 2)                -- returns 'He'
lpad ('Hello', 2, '-')           -- returns 'He'
lpad ('Hello', 2, '')            -- returns 'He'