Home  >  Article  >  Database  >  What is the role of trim in mysql

What is the role of trim in mysql

coldplay.xixi
coldplay.xixiOriginal
2020-10-27 16:14:353594browse

The function of trim function in mysql is to filter the specified string, the format is [TRIM([{BOTH | LEADING | TRAILING} [remstr] FROM] str)].

What is the role of trim in mysql

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn