TRIM function

TRIM is a string manipulation function that manipulates all string data types (BIT, BLOB, and CHARACTER), and removes trailing and leading singletons from a string.

SYNTAX

TRIM returns a new string of the same type as source_string, in which the leading, trailing, or both leading and trailing singletons have been removed. The term singleton refers to a single part (BIT, BYTE, or CHARACTER) within a string of that type.

If trim_singleton is not specified, a default singleton is assumed. The default singleton depends on the data type of source_string:
Character ' ' (space)
BLOB X'00'
Bit B'0'

If any parameter is NULL, the result is NULL.

It is often unnecessary to strip trailing blanks from character strings before comparison, because the rules of character string comparison mean that trailing blanks are not significant.

The following examples illustrate the behavior of the TRIM function:
TRIM(TRAILING 'b' FROM 'aaabBb')
returns 'aaabB'.
TRIM('  a  ')
returns 'a'.
TRIM(LEADING FROM '  a  ')
returns 'a '.
TRIM('b' FROM 'bbbaaabbb')
returns 'aaa'.
Related concepts
ESQL overview
Related tasks
Developing ESQL
Selecting a subfield from a larger field
Related reference
Syntax diagrams: available types
ESQL string manipulation functions