SQL/MX 3.1 Reference Manual (H06.23+, J06.12+)

SQL/MX Functions and Expressions
HP NonStop SQL/MX Release 3.1 Reference Manual663850-001
9-145
RPAD Function
RPAD Function
The RPAD function replaces the rightmost specified number of characters in a
character expression with a padding character or string. With the
ANSI_STRING_FUNCTIONALITY CQD set to ON, the function pads the right side of a
character expression with the specified string.
character-expr
is an SQL character value expression. The operand is the result of evaluating
character-expr. See Character Value Expressions on page 6-41.
count
specifies the number of characters. The count must be greater than or equal to
zero of exact numeric data type and with a scale of zero. For considerations of
count based on CQD ANSI_STRING_FUNCTIONALITY, see Examples of RPAD
on page 9-145.
pad-character
specifies the padding character or a string. If no pad-character is specified,
spaces is the padding character. For KANJI or KSC5601, the code value of
pad-character is hexadecimal 2020.
Examples of RPAD
The behavior of the RPAD function when the ANSI_STRING_FUNCTIONALITY CQD
is set to ON and the corresponding examples are described below.
The count specifies the number of characters to be returned. It is the length of the
result string.
If count is smaller than the length of the character-expr, the character-expr is
truncated. If count is equal to the length of the character-expr, the value of the
character-expr is retained. If count is greater than the length of the
character-expr, the character-expr is right-padded with the pad-character.
The following RPAD function truncates the string 'kite' because the specified
count is less than the string size and returns 'ki':
RPAD('kite', 2)
The following RPAD function returns the original string 'go fly a kite' because
count is equal to length of the string:
RPAD('go fly a kite', 13, 'z')
RPAD (character-expr,count [,pad-character])