DB2 Scalar functions - RPAD
The RPAD function returns a string composed of string-expression padded on the right, with pad or blanks.
The schema is SYSIBM.
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.
If pad is not specified, the pad character is determined as follows:
The data type of the result depends on the data type of the string-expression:
The result of the function is a varying length string that has the same string unit and code page as string-expression. The value of string-expression and the value of pad must have compatible data types. If the string-expression and pad have different code pages, then pad is converted to the code page of string-expression. If either string-expression or pad is FOR BIT DATA or binary, no character conversion occurs.
The length attribute of the result depends on whether the value for integer is available when the SQL statement containing the function invocation is compiled (for example, if it is specified as a constant or a constant expression) or available only when the function is executed (for example, if it is specified as the result of invoking a function). When the value is available when the SQL statement containing the function invocation is compiled, if integer is greater than zero, the length attribute of the result is integer. If integer is 0, the length attribute of the result is 1. When the value is available only when the function is executed, the length attribute of the result is determined according to the following table:
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 result string. If integer is less than the actual length of string-expression, the actual length is integer and the result is truncated.
If any argument can be null, the result can be null; if any argument is null, the result is the null value.
Chris
Meg
Jeff
SELECT RPAD(NAME,15,'.' ) AS NAME FROM T1;
returns:
NAME --------------- Chris.......... Meg............ Jeff...........
SELECT RPAD(NAME,15,'123' ) AS NAME FROM T1;
NAME --------------- Chris1231231231 Meg123123123123 Jeff12312312312
SELECT RPAD(NAME,5,'.' ) AS NAME FROM T1;
NAME ----- Chris Meg.. Jeff.
SELECT RPAD(RTRIM(NAME),15,'.' ) AS NAME FROM T1;
SELECT RPAD(NAME,4,'.' ) AS NAME FROM T1;
NAME ---- Chri Meg. Jeff