Last index of a given substring in MySQL

前端 未结 6 665
余生分开走
余生分开走 2020-12-02 16:27

We can find the index of the first occurrence of a given substring in MySQL using the INSTR() function as follows.

SELECT instr(\'Have_a_good_da         


        
6条回答
  •  春和景丽
    2020-12-02 17:09

    If you don't want the overhead of REVERSE use the following:

    LEFT
    (
       'Have_a_good_day', 
       LENGTH('Have_a_good_day') - LENGTH(SUBSTRING_INDEX('Have_a_good_day','_',-1))-1
    )
    

提交回复
热议问题