数据库有个title字段,数据全部是XXX_XXXXX_XXXX 这种格式,其中X代表任何汉字,想截取右边第一个_开始向右的字串,不包含“_”。
例如字段某一记录为  电脑_手机_硬件_电脑知识
我只想要“电脑知识”问题补充: (1)汉字个数也不一样
(2)我需要update 数据库的title,也 就是说我想用截取后的title替换现在的title

解决方案 »

  1.   

    update tt set title=SUBSTRING_INDEX('电脑_手机_硬件_电脑知识','_',-1)
    or
    update tt set title=SUBSTRING_INDEX( title,'_',-1)
      

  2.   

    update table_name set title=substring_index(title,'_',-1)
      

  3.   


    mysql> select SUBSTRING_INDEX('电脑_手机_硬件_电脑知识','_',-1);
    +---------------------------------------------------+
    | SUBSTRING_INDEX('电脑_手机_硬件_电脑知识','_',-1)                 |
    +---------------------------------------------------+
    | 电脑知识                                                |
    +---------------------------------------------------+
    1 row in set (0.00 sec)mysql>
      

  4.   

    update table1 set title=substring_index(title,'_',-1);