TRIM
On this page
Removes padding from the ends of the given string.
Syntax
TRIM ([[BOTH | LEADING | TRAILING] [padding] FROM] str)
Arguments
-
padding: any string or binary object (optional, defaults to " ")
-
str: any string or binary object
If no keyword is specified, defaults to BOTH
.
Return Type
String
Examples
Note
This function removes only space " " characters.\t
, newline \n
, etc are preserved.
SELECT TRIM(' ohai ') AS t,TRIM(LEADING FROM ' ohai ') AS l,TRIM(TRAILING FROM ' ohai ') AS r;
+------+-----------+----------+
| t | l | r |
+------+-----------+----------+
| ohai | ohai | ohai |
+------+-----------+----------+
SELECT TRIM("abra" FROM "abracadabra") AS t;
+------+
| t |
+------+
| cad |
+------+
Caution
Implicit Collation
When character_
is set to utf8
, string literals with characters using 4-byte encoding are implicitly assigned binary collation and processed as a sequence of bytes rather than characters.utf8mb4
character set.
For more information, refer to Implicit Collation in Special Cases.
Related Topics
Last modified: April 4, 2023