Does the MySQL TRIM function not trim line breaks or carriage returns?

后端 未结 10 1834
旧时难觅i
旧时难觅i 2020-12-03 13:58

From my experiments, it does not appear to do so. If this is indeed true, what is the best method for removing line breaks? I\'m currently experimenting with the parameters

10条回答
  •  旧时难觅i
    2020-12-03 14:06

    Yes, Trim() will work in MySQL. You have two choices.

    1) select it out:

    select trim(BOTH '\n' from [field_name]) as field
    

    If that doesn't work, try '\r', if that doesn't work, try '\n\r'.

    2) replace the bad data in your table with an update...

    update [table_name] set [field_name] = trim(BOTH '\n' from [field_name])
    

    I recommend a select first to determine which line break you have (\r or \n).

提交回复
热议问题