denyy
answered May 31 '22 00:00
TRIM() function in MySQL is used to remove leading and trailing space/characters from data.
Syntax :
TRIM([{BOTH | LEADING | TRAILING} [remstr] FROM] str)
Parameter : TRIM() function in MySQL use parameter as following:
BOTH | LEADING | TRAILING :
BOTH or LEADING or TRAILING any one can be used in TRIM() function.
if BOTH option is set than it tell the TRIM() function to remove both leading and trailing unwanted characters from a string .
if LEADING option is set than it tell the TRIM() function to remove leading unwanted characters from a string .
if TRAILING option is set than it tell the TRIM() function to remove trailing unwanted characters from a string .
the TRIM() function uses the BOTH as default option.
removed_str : It is a string which we want to remove. If not given, spaces will be removed.
str : It identifies the string from which we want to remove removed_str.
Returns : It returns a string that has unwanted characters removed.
SELECT TRIM(TRAILING FROM " DATA ")
returns : DATA
SELECT TRIM(LEADING FROM " DATA ")
returns : DATA
SELECT TRIM(TRAILING "A" FROM " DATA")
returns : DAT
SELECT TRIM(LEADING "D" FROM " DATA")
returns : ATA
SELECT TRIM(LEADING "d" FROM "DATA")
returns : DATA
TRIM function have case insensitive replace the string