RPAD Function
The RPAD function returns a copy of source_string that is right-padded to the total number of characters that the length argument specifies.
Element | Description | Restrictions | Syntax |
---|---|---|---|
length | The total number of characters in the returned string | Must be an expression, constant, column, or host variable that returns an integer | Literal Number |
pad_string | String that specifies the pad character or characters | Must be an expression, column, constant, or host variable of a data type that can be converted to a character data type | Expression |
source_string | String that serves as input to the RPAD function | Same as for pad_string | Expression |
Any argument to the RPAD function must be of a built-in data type.
The pad_string parameter specifies the pad character or characters to be used to pad the source string.
The series of pad characters occurs as many times as necessary to make the return string reach the length that length specifies. The series of pad characters in pad_string is truncated if it is too long to fit into length. If you omit the pad_string parameter, the default value is a single blank space (the ASCII 32 character).
The return data type is based on the source_string and pad_string arguments, if both are specified. If a host variable is the source, the return value is either NVARCHAR or NCHAR, according to the length of the returned string, using the return type promotion rules that the section Return Types from the CONCAT Function describes.
The UNLOAD feature of DB-Access truncates trailing blanks in CHAR or NCHAR columns, even if the RPAD function has appended blank characters to the data value. You must explicitly cast the CHAR or NCHAR value to a VARCHAR, LVARCHAR, or NVARCHAR data type if you need UNLOAD to preserve trailing blank characters or nonprintable characters in a value that RPAD returns.
SELECT RPAD('Where are you', 18, '?!')
FROM mytable;
(constant) |
---|
Where are you?!?!? |