Removes blank characters or characters from the end of a string.
If you do not specify a trim_set parameter in the expression, rtrim removes both single-byte and double-byte spaces from the end of a string.
If you use rtrim to remove characters from a string, rtrim compares the trim_set to each character in the string argument, character-by-character, starting with the right side of the string. If the character in the string matches any character in the trim_set, rtrim removes it. The rtrim function continues comparing and removing characters until it fails to find a matching character in the trim_set. It returns the string without the matching characters.
Syntax
sff:rtrim(str, trim_set)
The following table describes the arguments:
Argument
Required/
Optional
Description
string
Required
Any string value. Passes the values that you want to trim. You can enter any valid transformation expression. Use operators to perform comparisons or concatenate strings before removing blank characters from the end of a string.
You must enclose the string value within single or double quotation marks.
To pass a NULL value, you must specify an empty sequence in the following format: ()
trim_set
Optional
Any string value. Passes the characters that you want to remove from the end of the string. You can also enter a text literal.
You must enclose the string value within single or double quotation marks.
To pass a NULL value, you must specify an empty sequence in the following format: ()
The rtrim function is case sensitive. For example, if you want to remove the 'o' character from the string 'Alfredo', you would enter 'o', not 'O'.
Return Value
String. The string values with the specified characters in the trim_set argument removed.
NULL if a value passed to rtrim is NULL. If the trim_set is NULL, rtrim returns NULL.
Example
The following expression removes the characters ‘re’ from the strings in the LAST_NAME column:
sff:rtrim( LAST_NAME, 're')
The following table lists some sample values and return values:
LAST_NAME
RETURN VALUE
Nelson
Nelson
Page
Pag
Osborne
Osborn
NULL
NULL
Sawyer
Sawy
H. Bender
H. Bend
Steadman
Steadman
The rtrim function removes ‘e’ from Page even though ‘r’ is the first character in the trim_set. This is because rtrim searches, character-by-character, for the set of characters you specify in the trim_set argument. If the last character in the string matches the first character in the trim_set, rtrim removes it. If, however, the last character in the string does not match, rtrim compares the second character in the trim_set. If the second from last character in the string matches the second character in the trim_set, rtrim removes it, and so on. When the character in the string fails to match the trim_set, rtrim returns the string and evaluates the next row.
In the last example, the last character in Nelson does not match any character in the trim_set argument, so rtrim returns the string 'Nelson' and evaluates the next row.
Tips for rtrim
Use rtrim with CONCAT to remove trailing blank characters after you concatenate two strings.
You can also remove multiple sets of characters by nesting rtrim. For example, to remove trailing blank characters and the character ‘t’ from the end of each string in a column of names, you might create an expression similar to the following: