Home > Database > Mysql Tutorial > 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?

王林
Release: 2023-08-30 11:49:02
forward
1198 people have browsed it

我们如何从 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)
Copy after login

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

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

Syntax

RTRIM(String)
Copy after login

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

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 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