How can we eradicate leading and trailing space characters from a string in MySQL?

MySQLMySQLi Database

MySQL LTRIM() and RTRIM() functions can be used to eradicate leading and trailing spaces from a string.

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

Syntax

LTRIM(String)

Here, String, is the string, passed as an argument, whose leading space characters are to be removed.

Example

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

MySQL RTRIM() function is used to remove the trailing space characters from a string. Its syntax can be as follows −

Syntax

RTRIM(String)

Here, String, is the string, passed as an argument, whose trailing space characters are to be removed.

Example

mysql> Select RTRIM('Hello ');
+----------------------+
| RTRIM('Hello ')      |
+----------------------+
| Hello                |
+----------------------+
1 row in set (0.05 sec)
raja
Published on 20-Feb-2018 08:45:50
Advertisements