How can I remove the leading and trailing spaces both at once from a string without using MySQL LTRIM() and RTRIM() functions?


Other than LTRIM() and RTRIM() functions, MySQL has TRIM() function to remove leading and trailing function both at once from a string. The use of TRIM() function can be understood from the following example of a test_trim table which has a column ‘Name’ containing the names with leading and trailing spaces.

Example

mysql> Select Name, TRIM(Name)AS 'Name Without Spaces' from test_trim;
+---------------+---------------------+
| Name          | Name Without Spaces |
+---------------+---------------------+
| Gaurav        | Gaurav              |
| Rahul         | Rahul               |
| Aarav         | Aarav               |
+---------------+---------------------+
3 rows in set (0.00 sec)

Anjana
Anjana

e

Updated on: 06-Feb-2020

82 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements