A字段中 1,11,111,111111, 每个数字用逗号隔开。现在想通过MYSQL语法把1,(数字和逗号)删除掉,但用REPLACE方法的话会把凡是包含1,的都删除掉,不知道有没有完全匹配的方式只删除1,   其它数字与逗号保留mysql

解决方案 »

  1.   

    先把 1,11,111,111111, 变成 ,1,11,111,111111,  (前面加,)
    然后再使用REPLACE方法
      

  2.   

      ,1,11,111,111111,   MYSQL有办法把最左边的逗号删除掉吗?
      

  3.   

    可以right函数
    update table  set col=right(col,3)
      

  4.   

    刚写错了
    可以使用right函数
    update table  set col=right(col,length(col)-2) 
    可以使用substring函数
    update table  set col=substring(col,3) 
      

  5.   

    楼上方法不错。update table1 set A字段=mid(A字段,3,10000) where A字段 like '1,%';
      

  6.   

    如果你的格式是固定的,直接从第3个字符取
    mid(A字段,3)
      

  7.   

    当有多个1,1的时候,就处理不了了。def main():
        str='1,11,111,111111,1,23,11,111,11,1,2,11,'
        str1=[]
        for lst in str.split(','):
            if lst<>'1':
                #str1=str1+','+lst
                str1.append(lst)
        print ','.join(str1)
    if __name__ == '__main__':
        main()结果是:
    11,111,111111,23,11,111,11,2,11,
      

  8.   

    比较完美的方法:
    update company_department set Secures = trim(both ',' from replace(concat(',', Secures, ','), ',71,', ','));
      

  9.   

    Secures,是用逗号隔开的字符串所在的字段,71是需要删除的字符串