Skip to main content
Version: current [26.x]

Categories: String

TRIM

Removes leading, trailing, or both spaces or characters from a string.

Syntax

TRIM(LEADING or TRAILING or BOTH trim_expression varchar FROM expression varchar) → varchar

  • trim_expression (optional): The characters to trim.
  • expression: The expression to be trimmed.

Examples

TRIM example
SELECT TRIM('   dremio   ')
-- dremio
TRIM example
SELECT TRIM(LEADING 'x' FROM 'xxxDremio')
-- Dremio
TRIM example
SELECT TRIM(TRAILING 'x' FROM 'Dremioxxx')
-- Dremio
TRIM example
SELECT TRIM(BOTH 'x' FROM 'xxxDremioxxx')
-- Dremio
TRIM example
SELECT TRIM('xy' FROM 'xyxDremioxyy')
-- Dremio

Usage Notes

If you do not specify a keyword before trim_expression, it defaults to BOTH. If you do not specify trim_expression, it defaults to a space. Organizations using Oracle will always receive a NULL return if this function is used with an empty string.