MySQL truncate text with ellipsis

前端 未结 6 481
小鲜肉
小鲜肉 2021-01-04 01:14

Suppose I have a MySQL table of one column: \"Message\". It is of type TEXT. I now want to query all rows, but the text can be large (not extremely large but large) and I on

6条回答
  •  暖寄归人
    2021-01-04 01:43

    Here's a simple one line solution:

    IF(CHAR_LENGTH(message) > 10, CONCAT(LEFT(message, 7),"..."), message)
    

提交回复
热议问题