Home > Database > Mysql Tutorial > body text

What is the role of trim in mysql

coldplay.xixi
Release: 2020-10-29 16:15:59
Original
3615 people have browsed it

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'
Copy after login

The function to remove left spaces in mysql:

LTRIM(str);

mysql> SELECT LTRIM('  barbar');
        -> 'barbar'
Copy after login

The function to remove right spaces in mysql:

RTRIM(str):

mysql> SELECT RTRIM('barbar   ');
-> 'barbar'
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template