RPAD scalar function
The RPAD function returns a string that is padded on the right with blanks or a specified string.
The schema is SYSIBM.
The RPAD function returns a string composed of string-expression padded on the right, with pad or blanks. The RPAD function treats leading or trailing blanks in string-expression as significant. Padding will only occur if the actual length of string-expression is less than integer, and pad is not an empty string.
- string-expression
- An expression that specifies the source string. The expression must return a value that is a built-in string data type that is not a LOB.
- integer
- An integer constant that specifies the length of the result. The value must be zero or a positive integer that is less than or equal to n, where n is 32704 if string-expression is a character or binary string, or where n is 16352 if string-expression is a graphic string.
- pad
- An expression that specifies the string with which to pad. The
expression must return a value that is a built-in string data type
that is not a LOB. If pad is not specified,
the pad character is determined as follows:
- SBCS blank character if string-expression is a character string.
- DBCS blank character if string-expression is a graphic string.
- Hexadecimal zero (X'00'), if string-expression is a binary string.
The result of the function is a varying length string that has the same CCSID of string-expression. string-expression and pad must have compatible data types. If the string expressions have different CCSID sets, then pad is converted to the CCSID set of string-expression. If either string-expression or pad is FOR BIT DATA, no character conversion occurs. The actual length of the result is determined from integer.
The length attribute of the result depends on integer. If integer is greater than 0, the length attribute of the result is integer. If integer is 0, the length attribute of the result is 1.
The actual length of the result is determined from integer. If integer is 0, the actual length is 0, and the result is the empty string. If integer is less than the actual length of string-expression, the actual length is integer and the result is truncated.
The result can be null; if any argument is null, the result is the null value.
SELECT RPAD(NAME,15,'.' ) AS NAME
FROM T1;
The results are similar to the following output: NAME
---------------
Chris..........
Meg............
Jeff...........
SELECT RPAD(NAME,15,'123' ) AS NAME
FROM T1;
The results are similar to the following output: NAME
---------------
Chris1231231231
Meg123123123123
Jeff12312312312
SELECT RPAD(NAME,5,'.') AS NAME
FROM T1;
The results are similar to the following output: NAME
---------------
Chris
Meg..
Jeff.
SELECT RPAD(RTRIM(NAME),15,'.') AS NAME
FROM T1;
The results are similar to the following output: NAME
---------------
Chris..........
Meg............
Jeff...........