Categories: String


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


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

  • expression: The expression to be trimmed
  • trim_expression: The characters to trim


SELECT TRIM('    pancake    ')
-- pancake
SELECT TRIM(leading 'pan' from 'pancake')
-- cake
SELECT TRIM(trailing 'cake' from 'pancake')
-- pan
SELECT TRIM(both 'pan' from 'pancake pan')
-- cake
SELECT TRIM('pan' from 'pancake pan')
-- cake

Usage Notes

If you do not specify a keyword before expression, it defaults to BOTH. If you do not specify trim_expression, it defaults to a space.