String truncate on length, but no chopping up of words allowed

后端 未结 8 1692
旧巷少年郎
旧巷少年郎 2020-12-15 19:33

I want to limit a string field length in MYSQL on a certain length, but I don\'t want any chopping up of words to occur.

When I do:

SELECT SUBSTRING(         


        
8条回答
  •  隐瞒了意图╮
    2020-12-15 20:23

    In SQL it would be...

    select Substring('Business Analist met focus op wet- en regelgeving', 0 , 28 + 2 - CharIndex(' ',  REVERSE(SUBSTRING('Business Analist met focus op wet- en regelgeving', 0, 28 + 1 )),0))
    

    I dont know if all these functions are available in MYSQL

    EDIT: I think for MYSQL substitute "Locate" for "CharIndex"

提交回复
热议问题