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: 2020-02-06T06:51:53+05:30

178 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements