数据库中有一列字符串,如下
100,1,1,0,0
100,1,2,0,0
100,2,3,4,2
...希望将前面的100修改为1,如下:
1,1,1,0,0
1,1,2,0,0
1,2,3,4,2
...求sql,谢谢!

解决方案 »

  1.   

    假设格式固定
    update tt set f1=concat('1',mid(f1,instr(f1,'100,')+4))
    or
    update tt set f1=replace(f1,'100','1')
      

  2.   

    update tt set f1=concat('1,',mid(f1,instr(f1,'100,')+4))
      

  3.   


    mysql> select replace('100,1,1,0,0',100,1);
    +------------------------------+
    | replace('100,1,1,0,0',100,1) |
    +------------------------------+
    | 1,1,1,0,0                    |
    +------------------------------+
    1 row in set (0.00 sec)
      

  4.   

    select replace('100,1,1,0,0',100,1);
      

  5.   

    update table1 set 有一列字符串=concat('1',mid(有一列字符串,4,100))
    where 有一列字符串 like '100,%'
      

  6.   

    谢谢大家,问题解决了,但是这个为什么报错啊?
    update fun_build set base_msg = concat('100',substr(base_msg,3)  where  player_id = 'hao' and sub_type = 28;
      

  7.   

    谢谢大家,一起一直用oracle,突然用mysql感觉好不习惯。