zoukankan      html  css  js  c++  java
  • 设置customer_id

     update t_user_identification u
         set u.customer_id = (select c.customer_id
                                from t_customer c
                               where exists (select 1
                                        from t_user us
                                       where us.customer_id = c.customer_id
                                         and exists
                                       (select 1
                                                from t_user_login_way y
                                               where y.user_id = us.user_id
                                                 and y.user_name = u.open_id
                                                 and y.user_type = '02'))
                                 and rownum <= 1)
       where u.identify_status in ('1');

     上面的方法有个缺陷,当数据过多时,数据库会因为执行时间太长而报错ORA-01555,导致全盘扫描中断,

    改成下面这样问题就都解决啦

      
    declare
     v_num number;
    begin
      v_num := 0;
      for f in (select id,open_id from t_user_identification where identify_status = '1') loop  
      update t_user_identification u
         set u.customer_id = (select c.customer_id
                                from t_customer c
                               where exists (select 1
                                        from t_user us
                                       where us.customer_id = c.customer_id
                                         and exists
                                       (select 1
                                                from t_user_login_way y
                                               where y.user_id = us.user_id
                                                 and y.user_name = f.open_id
                                                 and y.user_type = '02'))
                                 and rownum <= 1)
       where u.identify_status in ('1') and u.id = f.id;
       v_num := v_num + 1;
       if v_num > 50 then
        begin
        commit;
        v_num := 0;
        end;
        end if;
    end loop;
    commit;
    end;
  • 相关阅读:
    day3 集合
    进度条
    day3 文件操作 seek tell 修改
    day3 函数
    同学满分代码,购物车。
    day2杂---三元运算 is
    模块sys os
    day2--列表/元组/字符串/字典
    一、Git配置
    四、TestNG 批量执行脚本Runner.xml
  • 原文地址:https://www.cnblogs.com/yinyl/p/8436328.html
Copyright © 2011-2022 走看看