欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

批量更新MySql数据

程序员文章站 2022-05-24 23:45:09
...
def update_uid(self):
    """
    3.修改更新uid
    :rtype: object
    """
    lon_list = []
    update_str = ""
    for i in range(10000):
        try:
            lon, uids = self.r.get('mysql_field')
        except:
            break
        update_str += "WHEN {} THEN '{}' ".format(lon, uids)
        lon_list.append(lon)

    sql1 = """
           UPDATE {}
              SET uid = CASE lon

              {}
              END
      """.format(self.mysql_collection, update_str)
    print("这是分割线")
    print(lon_list, 22222222222222222222)
    sql2 = """WHERE {} IN {}""".format('lon', tuple(lon_list))
    sql = sql1 + sql2
    print(sql)
    with self.connection_mysql.cursor() as cursor:
        cursor.execute(sql)
    self.connection_mysql.commit()
    print("批量更新数据成功")
相关标签: update mysql