RTRIM

The RTRIM function removes blanks or hexadecimal zeroes from the end of a string expression.

Read syntax diagramSkip visual syntax diagram
>>-RTRIM--(--expression--)-------------------------------------><

expression
An expression that returns a value of any built-in numeric or string data type.1 A numeric argument is cast to a character string before evaluating the function. For more information about converting numeric to a character string, see VARCHAR.
  • If the argument is a binary string, then the trailing hexadecimal zeros (X'00') are removed.
  • If the argument is a DBCS graphic string, then the trailing DBCS blanks are removed.
  • If the first argument is a Unicode graphic string, then the trailing UTF-16 or UCS-2 blanks are removed.
  • If the first argument is a UTF-8 character string, then the trailing UTF-8 blanks are removed.
  • Otherwise, trailing SBCS blanks are removed.

The data type of the result depends on the data type of string-expression:

Data type of string-expression Data type of the Result
CHAR or VARCHAR VARCHAR
CLOB CLOB
GRAPHIC or VARGRAPHIC VARGRAPHIC
DBCLOB DBCLOB
BINARY or VARBINARY VARBINARY
BLOB BLOB

The length attribute of the result is the same as the length attribute of string-expression. The actual length of the result is the length of the expression minus the number of bytes removed. If all characters are removed, the result is an empty string.

If the first argument can be null, the result can be null; if the first argument is null, the result is the null value.

The CCSID of the result is the same as that of the string.

Example

  • Assume the host variable HELLO of type CHAR(9) has a value of 'Hello '.
    SELECT RTRIM(:HELLO)
        FROM SYSIBM.SYSDUMMY1
    Results in: 'Hello'.
1 The RTRIM function returns the same results as: STRIP(expression,TRAILING)