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


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)

Updated on: 06-Feb-2020

92 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements