Home  >  Article  >  Database  >  How can we eliminate leading and trailing space characters from strings in MySQL?

How can we eliminate leading and trailing space characters from strings in MySQL?

王林
王林forward
2023-08-30 11:49:021048browse

我们如何从 MySQL 中的字符串中消除前导和尾随空格字符?

MySQL LTRIM() and RTRIM() functions can be used to eliminate leading and trailing spaces from strings.

MySQL LTRIM() function is used to remove leading space characters from a string. Its syntax is as follows -

Syntax

LTRIM(String)

Here, String is the string passed as parameter and its leading space characters will be removed.

Example

mysql> Select LTRIM(' Hello');
+--------------------+
| LTRIM(' Hello')    |
+--------------------+
| Hello              |
+--------------------+
1 row in set (0.00 sec)

The MySQL RTRIM() function is used to remove trailing space characters from a string. Its syntax is as follows -

Syntax

RTRIM(String)

Here, String is the string passed as parameter and its trailing space characters will be removed.

Example

mysql> Select RTRIM('Hello ');
+----------------------+
| RTRIM('Hello ')      |
+----------------------+
| Hello                |
+----------------------+
1 row in set (0.05 sec)

The above is the detailed content of How can we eliminate leading and trailing space characters from strings in MySQL?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete