RTRIM
Removes spaces at the end of a string.
MySQL 8.1
RTRIM(str)Parameters
- strVARCHAR
- Source string
Return value
A string without trailing spaces; tabs and line breaks are kept
Examples
Spaces removed on the right
MySQL 8.1
SELECT CONCAT('[', RTRIM(' Hello '), ']') AS result;Length before and after RTRIM
MySQL 8.1
SELECT CHAR_LENGTH('Hello ') AS before_rtrim,
CHAR_LENGTH(RTRIM('Hello ')) AS after_rtrim;Details
Only spaces are removed. To remove other characters, use TRIM(TRAILING '.' FROM str). In PostgreSQL, RTRIM takes a second argument with the set of characters to remove, but MySQL has no such argument.