The function of trim function in mysql is to filter the specified string, the format is [TRIM([{BOTH | LEADING | TRAILING} [remstr] FROM] str)].
The trim function can filter the specified string:
Full format: TRIM([{BOTH | LEADING | TRAILING} [remstr] FROM ] str)
Simplified format: TRIM([remstr FROM] str)
Returns the string str in which all remstr prefixes and/or suffixes have been removed. If none of the classifiers BOTH, LEADIN or TRAILING is given, BOTH is assumed. remstr is optional and can remove spaces if not specified.
mysql> SELECT TRIM(' bar '); -> 'bar' mysql> SELECT TRIM(LEADING 'x' FROM 'xxxbarxxx'); --删除指定的首字符 x -> 'barxxx' mysql> SELECT TRIM(BOTH 'x' FROM 'xxxbarxxx'); --删除指定的首尾字符 x -> 'bar' mysql> SELECT TRIM(TRAILING 'xyz' FROM 'barxxyz'); --删除指定的尾字符 x -> 'barx'
The function to remove left spaces in mysql:
LTRIM(str);
mysql> SELECT LTRIM(' barbar'); -> 'barbar'
The function to remove right spaces in mysql:
RTRIM(str):
mysql> SELECT RTRIM('barbar '); -> 'barbar'
More related free learning recommendations: mysql tutorial(video)
The above is the detailed content of What is the role of trim in mysql. For more information, please follow other related articles on the PHP Chinese website!