共用方式為


trim函式

適用於:核取記號為「是」Databricks SQL 核取記號為「是」Databricks Runtime

去除 str的前置或尾端空格字元。

str移除前置或尾端 trimStr 字元。

語法

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)

引數

  • trimStr:包含要修剪字符集的 STRING 表示式。
  • str:要修剪的 STRING 表示式。

傳回

STRING

範例

> 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