TRIM([[LEADING|TRAILING|BOTH] [substring] FROM] string)

Description: Returns string with any leading or trailing occurrences of substring removed, according to whether LEADING or TRAILING is specified.

If neither LEADING nor TRAILING is specified, BOTH will be assumed, which will remove occurrences of substring from both ends of string.

If substring is not specified, spaces will be assumed.

Examples:

  • TRIM(LEADING 'www.' FROM 'www.mysite.com') returns mysite.com.

  • TRIM(LEADING 'w' FROM 'www.mysite.com') returns .mysite.com.

  • TRIM('m' FROM 'mysite.com') returns ysite.co.

  • TRIM(' mysite.com ') returns mysite.com.

See also: LTRIM(), RTRIM()

Get Sams Teach Yourself MySQL in 21 Days, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.