MySQL TRIM 函数
-
定义和用法
TRIM - 返回字串。 -
语法
TRIM([{BOTH | LEADING | TRAILING} [remstr] FROM] str),TRIM([remstr FROM] str)
返回删除了所有remstr前缀或后缀的字符串str。 如果没有给出两个说明符BOTH,LEADING或TRAILING,则假定两者均为。 remstr是可选的,如果未指定,则删除空格。 -
示例
尝试一下mysql> SELECT TRIM(' bar '); +---------------------------------------------------------+ | TRIM(' bar ') | +---------------------------------------------------------+ | bar | +---------------------------------------------------------+ 1 row in set (0.00 sec) mysql> SELECT TRIM(LEADING 'x' FROM 'xxxbarxxx'); +---------------------------------------------------------+ | TRIM(LEADING 'x' FROM 'xxxbarxxx') | +---------------------------------------------------------+ | barxxx | +---------------------------------------------------------+ 1 row in set (0.00 sec) mysql> SELECT TRIM(BOTH 'x' FROM 'xxxbarxxx'); +---------------------------------------------------------+ | TRIM(BOTH 'x' FROM 'xxxbarxxx') | +---------------------------------------------------------+ | bar | +---------------------------------------------------------+ 1 row in set (0.00 sec) mysql> SELECT TRIM(TRAILING 'xyz' FROM 'barxxyz'); +---------------------------------------------------------+ | TRIM(TRAILING 'xyz' FROM 'barxxyz') | +---------------------------------------------------------+ | barx | +---------------------------------------------------------+ 1 row in set (0.00 sec)