Use LTRIM and RTRIM Functions to Update MySQL Table



We can use LTRIM() and RTRIM functions with MySQL update clause so that the values, after removing space characters, in the table can be updated. Following examples will demonstrate it −

Example

Suppose we know that there can be some space characters in the values of ‘Name’ column of table ‘Student’ then with the help of following single query we can remove the space characters from that column’s value and also update the table −

mysql> Update Student SET Name = LTRIM(Name);
Query OK, 0 rows affected (0.07 sec)
Rows matched: 5 Changed: 0 Warnings: 0

mysql> Update Student SET Name = RTRIM(Name);
Query OK, 0 rows affected (0.00 sec)
Rows matched: 5 Changed: 0 Warnings: 0
Updated on: 2020-02-06T06:52:34+05:30

385 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements