TRIM([{BOTH | LEADING | TRAILING} [remstr] FROM] str), TRIM([remstr FROM] str)
TRIM mysql function is used for trimming a given character even left or right and if not given then both side. If trimming character is not passed with this function then this will remove white space form both side of string.
This returns the string str with all remstr prefixes or suffixes removed. If none of the specifiers BOTH, LEADING, or TRAILING is given, BOTH is assumed. remstr is optional and and if this not specified then spaces are removed.
Here I am giving some example which will explain you this function clearly-
mysql> SELECT TRIM(' MySQL ');
+--------------------------------+
| TRIM(' MySQL ') |
+--------------------------------+
| MySQL |
+--------------------------------+
1 row in set (0.00 sec)
mysql> SELECT TRIM(LEADING '?' FROM '?????MySQL?????');
+------------------------------------------+
| TRIM(LEADING '?' FROM '?????MySQL?????') |
+------------------------------------------+
| MySQL????? |
+------------------------------------------+
1 row in set (0.00 sec)
mysql> SELECT TRIM(TRAILING '?' FROM '?????MySQL?????');
+-------------------------------------------+
| TRIM(TRAILING '?' FROM '?????MySQL?????') |
+-------------------------------------------+
| ?????MySQL |
+-------------------------------------------+
1 row in set (0.00 sec)
mysql> SELECT TRIM(BOTH '?' FROM '?????MySQL?????');
+---------------------------------------+
| TRIM(BOTH '?' FROM '?????MySQL?????') |
+---------------------------------------+
| MySQL |
+---------------------------------------+
1 row in set (0.00 sec)
0 Comment(s)