Product Documentation

SQL Reference Guide

Previous Topic

Next Topic

RPAD function (extension)

Syntax

RPAD ( char_expression, length [, pad_expression] )

Description

The scalar function RPAD pads the character string corresponding to the first argument on the right with the character string corresponding to the third argument so that after the padding, the length of the result would be equal to the value of the second argument length.

Example

SELECT RPAD (name, 30)

FROM customer ;

SELECT RPAD (name, 30, '.')

FROM customer ;

Notes

  • 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 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 first L2 characters.
  • The result is of character type whose character set is same as that of it’s arguments.
  • If the argument expression evaluates to null, the result is null.

TOCIndex