Table of Contents

Search

  1. Preface
  2. Function reference
  3. Constants
  4. Operators
  5. Dates
  6. Functions
  7. System variables
  8. Datatype reference

Function Reference

Function Reference

RPAD

RPAD

Converts a string to a specified length by adding blanks or characters to the end of the string.

Syntax

RPAD(
first_string
,
length
[,
second_string
] )
Argument
Required/
Optional
Description
first_string
Required
Any string value. The strings you want to change. You can enter any valid expression.
length
Required
Must be a positive integer literal. Specifies the length you want each string to be. When
length
is a negative number, RPAD returns NULL.
second_string
Optional
Any string value. Passes the string you want to append to the right-side of the
first_string
values. Enclose the characters you want to add to the end of the string within single quotation marks, for example, 'abc'. This argument is case sensitive.
If you omit the second string, the function pads the end of the first string with blanks.

Return Value

String of the specified length.
NULL if a value passed to the function is NULL or if length is a negative number.

Example

The following expression returns the item name with a length of 16 characters, appending the string ‘.’ to the end of each item name:
RPAD( ITEM_NAME, 16, '.')
ITEM_NAME
RETURN VALUE
Flashlight
Flashlight......
Compass
Compass.........
Regulator System
Regulator System
Safety Knife
Safety Knife....
RPAD counts the length from left to right. So, if the first string is longer than the length, RPAD truncates the string from right to left. For example, RPAD(‘alphabetical’, 5, ‘x’) would return the string ‘alpha’. RPAD uses a partial part of the
second_string
when necessary.
The following expression returns the item name with a length of 16 characters, appending the string ‘*..*’ to the end of each item name:
RPAD( ITEM_NAME, 16, '*..*' )
ITEM_NAME
RETURN VALUE
Flashlight
Flashlight*..**.
Compass
Compass*..**..**
Regulator System
Regulator System
Safety Knife
Safety Knife*..*
The following expression shows how RPAD handles negative values for the
length
argument for each row in the ITEM_NAME column:
RPAD( ITEM_NAME, -5, '.')
ITEM_NAME
RETURN VALUE
Flashlight
NULL
Compass
NULL
Regulator System
NULL

0 COMMENTS

We’d like to hear from you!