MySQL Removing trailing linebreaks from a column

后端 未结 6 2069
夕颜
夕颜 2021-01-05 15:29

I want to remove trailing line breaks from my MySQL column. trim() only removes whitespaces but I also want to remove trailing linebreaks. Could anyone suggest?

6条回答
  •  一向
    一向 (楼主)
    2021-01-05 15:37

    Just ran into this problem, and took care of it like this.

    UPDATE table_name SET col_name = REPLACE(TRIM(TRAILING ' ' FROM col_name), 
                                             TRIM(TRAILING '\r' FROM col_name), 
                                             TRIM(TRAILING '\n' FROM col_name))
    

    This will remove new lines (\n), carriage returns (\r), and whitespace.

提交回复
热议问题