你好,游客 登录 注册 搜索
背景:
阅读新闻

根据ora_rowscn删除重复插入的数据

[日期:2014-01-06] 来源:Linux社区  作者:shushugood [字体:大 中 小]

今天下班前,突然接到局方电话,要求提供10月详单通话记录。

这下就开始整,结果不小心,把提取的记录全部插入到了详单表。这下好了,几十w条重复记录,在1000亿大表中,删除嘛。

--下面是解决方案:

--1.找出提交值 ora_rowscn

-- select scn_to_timestamp(ora_rowscn) from dual 查看提交时间

select /*+ parallel(12) */  dt.ora_rowscn,count(*) from  table_name(涉及隐私)  dt, table_b(涉及隐私) cp
where dt.starttime>=to_date('2013-10-05 00:00:00','yyyy-mm-dd hh24:mi:ss')
and dt.starttime<to_date('2013-10-06 00:00:00','yyyy-mm-dd hh24:mi:ss')
and dt.called in ('123456','xxxxx')
and substr(dt.caller,1,3) in ('..','..','....')
and dt.xxx=cp.xx
and cp.ldcflag=1
 --and dt.ora_rowscn=31902278734
 group by dt.ora_rowscn
 order by 2 desc
;

--
--验证时间
select scn_to_timestamp(31903242189) from dual

 
--验证条数
 --select 10910+1841 from dual
 
 --创建表
create table rowid_4 as
select rowid rowids from table_name (涉及隐私) dt
where dt.starttime>=to_date('2013-10-04 00:00:00','yyyy-mm-dd hh24:mi:ss')
and dt.starttime<to_date('2013-10-05 00:00:00','yyyy-mm-dd hh24:mi:ss')
and dt.ora_rowscn in (31901488022,31905491128)

--验证条数
select count(*) from rowid_4;

--根据rowid删除重复数据
delete /*+ parallel(8) nologging use_hash(dt ssd )*/ from  table_name (涉及隐私) dt 
where dt.rowid in (select rowids from rowid_4 ssd)

更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12

linux
相关资讯       ORA_ROWSCN 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款