Firebird Documentation Index → Firebird 2.1 Language Ref. Update → Internal functions → LPAD() |
Available in: DSQL, PSQL
Added in: 2.1
Description: Left-pads a string with spaces or with a user-supplied string until a given length is reached.
Result type: VARCHAR(32765) or BLOB
Syntax:
LPAD (str
,endlen
[,padstr
])
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(32765).If
padstr
is given and equals''
(empty string), no padding takes place.If
endlen
is less than the current string length, the string is truncated toendlen
, even ifpadstr
is the empty string.
If the external function LPAD
is declared in your database, it will override the internal function. To make the internal function available, DROP or ALTER the external function (UDF).
With (VAR)CHARs, it is generally wise to CAST the result to a smaller size. The default result length of 32765 may, in combination with other output columns, lead to a “block size exceeds implementation restriction” error.
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'
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.
See also: RPAD()
Firebird Documentation Index → Firebird 2.1 Language Ref. Update → Internal functions → LPAD() |