MySQL TRIM() Function
The TRIM()
function in MySQL removes leading and trailing spaces from a string. This is a very common data cleaning operation, used to standardize text data and ensure that extra whitespace doesn't interfere with comparisons or other operations.
TRIM(): Definition and Usage
Extra spaces at the beginning or end of a string (leading and trailing whitespace) are often unwanted. TRIM()
efficiently removes this extra whitespace, leaving only the essential string content. Spaces *within* the string are not affected.
Syntax
Syntax
TRIM(string)
Parameter Values
Parameter | Description |
---|---|
string |
The string from which you want to remove leading and trailing spaces. This is required. |
Example
Removing Whitespace
This example removes leading and trailing spaces from the string " SQL Tutorial ".
Syntax
SELECT TRIM(' SQL Tutorial ') AS TrimmedString;
Output
SQL Tutorial