zoukankan      html  css  js  c++  java
  • Oracle 删除大表中部分数据

    需求:

    项目中有一张表大概有7000多万条数据,造成表空间已满,需要清理部分数据,打算清理3000万。

    2B 做法:

    delete from table_name where ID > '40000000';

    备注:select count(1) from table_name where ID > 'his_batch_4000000';  的结果大概有3000万条数据。

    影响:

    删了N个小时也没执行完,最终强制停止,造成表被锁。(没有管理员权限,需要联系DBA 才能解锁)

    改进:

    declare
    ncount number;
    nrownumber number;
    begin
    nrownumber := 0;
    loop
    ncount := 0;

    select count(1)
    into ncount
    from table_name 
    where ID > 'his_batch_4000000'
    and rownum < 10000;
    if ncount > 0 then
    delete from table_name 
    where ID > 'his_batch_4000000'
    and rownum < 10000;
    commit;
    nrownumber := nrownumber + ncount;
    dbms_output.put_line(nrownumber);
    else
    exit;
    end if;

    end loop;
    end;

  • 相关阅读:
    2018年4月22日笔记
    2018年4月19日笔记
    2018年4月17日笔记
    2018年4月14日笔记
    2018年4月12日笔记
    课堂练习找水王
    评价软件
    第十一周进度条
    典型用户场景、用户场景描述
    构建之法阅读笔记04
  • 原文地址:https://www.cnblogs.com/gw811/p/4435777.html
Copyright © 2011-2022 走看看