zoukankan      html  css  js  c++  java
  • 修正MYSQL错误数据的一个存储过程

    -- 添加索引
    CREATE INDEX idx_STRUCTURE_ID ON t_resource_info(STRUCTURE_ID); 
    
    DROP PROCEDURE IF EXISTS `P_RepairSchemeIdError`;
    
    CREATE  PROCEDURE `P_RepairSchemeIdError`()
    BEGIN
        DECLARE v_scheme_id_int int ;
        DECLARE v_maxId int;
      DECLARE v_CurrentId int;
        set v_scheme_id_int=100003059;
        select MAX(id), MIN(id) into v_maxId,v_CurrentId from t_resource_info where scheme_id_int=v_scheme_id_int;
    
      while (v_CurrentId<v_maxId) do 
    
            UPDATE t_resource_info p INNER JOIN t_resource_structure pp ON p.STRUCTURE_ID = pp.STRUCTURE_ID
            SET p.SCHEME_ID_INT = pp.SCHEME_ID_INT WHERE p.SCHEME_ID_INT=v_scheme_id_int and p.id<v_CurrentId;
    
            set v_CurrentId=v_CurrentId+100000;
    
        end while; 
    
        UPDATE t_resource_info p INNER JOIN t_resource_structure pp ON p.STRUCTURE_ID = pp.STRUCTURE_ID
            SET p.SCHEME_ID_INT = pp.SCHEME_ID_INT WHERE p.SCHEME_ID_INT=v_scheme_id_int;
    END
    
    
    call P_RepairSchemeIdError;
  • 相关阅读:
    20191117-STD::讲解及求平均数例题
    计算机网络-ip分类
    游标cursor
    ajax
    django ORM
    urls
    templates
    views
    models
    setting
  • 原文地址:https://www.cnblogs.com/littlehb/p/5583642.html
Copyright © 2011-2022 走看看