|
<< Click to Display Table of Contents >> TRIM function |
![]() ![]()
|
Removes the trailing or leading character, or both, from a string.
TRIM([LEADING|TRAILING|BOTH] [trimmed_char] FROM column_reference)
Use TRIM to delete the leading or trailing character, or both, from a character value (column, literal, parameter, or caculated values). The TRIM function only deletes characters located in the specified position.
The first parameter indicates the position of the character to be deleted, and has one of the following values:
Value Description
| LEADING | Deletes the character at the left end of the string. |
| TRAILING | Deletes the character at the right end of the string. |
| BOTH | Deletes the character at both ends of the string. |
The trimmed character parameter specifies the character to be deleted, if present. Case-sensitivity is applied for this parameter. To make TRIM case-insensitive, use the UPPER function.
FROM specifies the character value from which to delete the character. The column reference for FROM can be a table column or a character literal.
Example variations:
TRIM syntax Result
TRIM(LEADING "_" FROM "_ABC_") "ABC_"
TRIM(TRAILING "_" FROM "_ABC_") "_ABC"
TRIM(BOTH "_" FROM "_ABC_") "ABC"
TRIM(BOTH "A" FROM "ABC") "BC"
When applied to retrieved data of a SELECT statement, the effect is transient and does not affect stored data. When applied to the update atoms of an UPDATE statement, the effect is persistent and permanently converts the case of the stored values.
TRIM can only be used with character columns or literals. To use on values of other data types, the values must first be converted to CHAR using the CAST function.
Note: the TRIM function cannot be used with memo or BLOB columns.