SqlExpression TRIM
From Eigenpedia
Contents |
Syntax
TRIM( source_string ); TRIM( trim_character FROM source_string ); TRIM( LEADING trim_character FROM source_string ); TRIM( TRAILING trim_character FROM source_string ); TRIM( BOTH trim_character FROM source_string );
Purpose
Removes repetitions of the specified character from either the beginning or the ending of a string. If LEADING keyword is used, the only the leftmost characters will be removed. If TRAILING, then only the rightmost characters will be removed, and if BOTH, then both leftmost and rightmost characters will be removed.
Input
- trim_character - the character to remove from the string. This is an optional parameter which defaults to a space character. An exception will be raised if trim_character is longer than one character or if it is the empty string.
- source_string - the string from which the characters will be removed
Output
- the string with removed repetitions; returns null on null input.
Example
| Function | Result |
|---|---|
| TRIM('a' FROM 'aaaaAbaabaa') | Abaab |
| TRIM( BOTH 'a' FROM 'aaaaAbaabaa') | Abaab |
| TRIM( LEADING 'a' FROM 'aaaaAbaabaa') | Abaabaa |
| TRIM( TRAILING 'a' FROM 'aaaaAbaabaa') | aaaaAbaab |
| TRIM(' sdf ') | sdf |

