trim
function
Applies to: Databricks SQL Databricks Runtime
Removes the leading or trailing space characters from str
.
Removes the leading or 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
: ASTRING
expression with a set of characters to be trimmed.str
: ASTRING
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
> SELECT trim(BOTH 'sl' COLLATE UTF8_BINARY FROM 'SSparkSQLS');
SSparkSQLS
> SELECT trim(BOTH 'sl' COLLATE UTF8_LCASE FROM 'SSparkSQLS');
parkSQ