Link Search Menu Expand Document

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 <target_string>)
Parameter Description
[ LEADING | TRAILING | BOTH ] Specifies which part or parts of the <target_string> to remove the defined <trim_character>. If unspecified, this defaults to BOTH.

LEADING - trims from the beginning of the specified string

TRAILING - 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.
<target_string> The string to be trimmed.

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$