trim function

Applies to: check marked yes Databricks SQL check marked yes Databricks Runtime

Removes the leading and trailing space characters from str.

Removes the leading space characters from str.

Removes the trailing space characters from str.

Removes the leading and trailing trimStr characters from str.

Removes the leading trimStr characters from str.

Removes the trailing trimStr characters from str.

Syntax

trim(str)

trim(BOTH FROM str)
trim(LEADING FROM str)
trim(TRAILING FROM str)
trim(trimStr FROM str)
trim(BOTH trimStr FROM str)
trim(LEADING trimStr FROM str)
trim(TRAILING trimStr FROM str)

Arguments

  • trimStr: A STRING expression with a set of characters to be trimmed.

  • str: A STRING expression to be trimmed.

Returns

A STRING.

Examples

> SELECT '+' || trim('    SparkSQL   ') || '+';
 +SparkSQL+
> SELECT '+' || trim(BOTH FROM '    SparkSQL   ') || '+';
 +SparkSQL+
> SELECT '+' || trim(LEADING FROM '    SparkSQL   ') || '+';
 +SparkSQL   +
> SELECT '+' || trim(TRAILING FROM '    SparkSQL   ') || '+';
 +    SparkSQL+
> SELECT trim('SL' FROM 'SSparkSQLS');
 parkSQ
> SELECT trim(BOTH 'SL' FROM 'SSparkSQLS');
 parkSQ
> SELECT trim(LEADING 'SL' FROM 'SSparkSQLS');
 parkSQLS
> SELECT trim(TRAILING 'SL' FROM 'SSparkSQLS');
 SSparkSQ