TRIM
Removes all specified characters from the start, end, or both sides of a string. By default removes all consecutive occurrences of common whitespace (ASCII character 32) from both ends of a string.
Syntax
TRIM( [LEADING | TRAILING | BOTH] <trim_character> FROM <expression>)
Parameters
Parameter | Description | Supported input types |
---|---|---|
LEADING | TRAILING | BOTH | Specifies which part or parts of the <expression> to remove the defined <trim_character> . | If unspecified, this defaults to BOTH .LEADING - trims from the beginning of the specified stringTRAILING - trims from the end of the specified string. BOTH - trims from the beginning and the end of the specified string. |
<trim_character> | The characters to be removed. | TEXT |
<expression> | The string to be trimmed. | TEXT |
Return Type
TEXT
Example
In the example below, no part of the string is specified for TRIM
, so it defaults to BOTH
.
SELECT
TRIM('$' FROM '$Hello world$') AS res;
Returns: Hello world
This next example trims only from the start of the string because the LEADING
parameter is specified.
SELECT
TRIM( LEADING '$' FROM '$Hello world$') AS res;
Returns: Hello world$