>>-TRIM--(--+-----------------------------------------+--expression--)->< | .-BOTH-----. | '-+----------+--+-----------------+--FROM-' +-B--------+ '-strip-character-' +-LEADING--+ +-L--------+ +-TRAILING-+ '-T--------'
The TRIM function removes blanks or another specified character from the end or beginning of a string expression.
The first argument, if specified, indicates whether characters are removed from the end or beginning of the string. If the first argument is not specified, then the characters are removed from both the end and the beginning of the string.
The data type of the result depends on the data type of expression:
Data type of 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 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.
The SRTSEQ attribute does not apply to the TRIM function.
SELECT TRIM(:HELLO), TRIM( TRAILING FROM :HELLO) FROM SYSIBM.SYSDUMMY1Results in 'Hello' and ' Hello' respectively.
SELECT TRIM( L '0' FROM :BALANCE ) FROM SYSIBM.SYSDUMMY1Results in: '345.50'
SELECT TRIM( BOTH
FROM
)
FROM SYSIBM.SYSDUMMY1
Results in:
(C) Copyright IBM Corporation 1992, 2006. All Rights Reserved.