Product Documentation

SQL Reference Guide

Previous Topic

Next Topic

LPAD function (extension)


LPAD ( char_expression, length [, pad_expression] )


The scalar function LPAD pads the character string corresponding to the first argument on the left with the character string corresponding to the third argument so that after the padding, the length of the result is length.


SELECT LPAD (name, 30)

FROM customer ;

SELECT LPAD (name, 30, '.')

FROM customer ;


  • The first argument to the function must be of character type.
  • The second argument to the function must be of type INTEGER.
  • The third argument, if specified, must be of character type.
  • If one of the arguments is a literal and the other one a field reference, the operation is possible only if the literal is convertible to the character set of the field reference. Otherwise an error is returned.
  • If the third argument is not specified, the default value is a string of length one containing one blank.
  • If L1 is the length of the first argument and L2 is the value of the second argument, then:
    • If L1 is less than L2, the number of characters padded is equal to L2 - L1.
    • If L1 is equal to L2, no characters are padded and the result string is the same as the first argument.
    • If L1 is greater than L2, the result string is equal to the first argument truncated to the first L2 characters.
  • The result is of character type whose character set is same as that of the arguments.
  • If the argument expression evaluates to null, the result is null.