oracle 复制删除重复数据

来源:互联网 发布:网络名字伤感两个字 编辑:程序博客网 时间:2024/06/06 00:11



最简单的复制:

insert into A (kcdm,zklb,kksj_i) select kcdm,zklb,kksj_i from B


产生疑惑的地方: 如果A有一个自增的ID, 语句该怎么写?

开始想法: insert into A (id,kcdm,zklb,kksj_i) select seq_a_id.nextval,kcdm,zklb,kksj_i from B   但是seq_a_id.nextval 是A的,select from B能获取到吗?明显很难。


如果A有自增的ID,这个时候需要创建seq和对应的trigger,语句和上面一样。可以自动生成ID。



删除重复数据:


简单删除 : delete from B where b.kcdm = (select kcdm from A )


多列删除: delete from exam_kkkc a where exists (select kcdm,zklb  from tp_global_kkkc_history b where a.kcdm=b.kcdm and a.zklb = b.zklb)

              delete from exam_kkkc a where exists (select b.kcdm,b.zklb from tp_global_kkkc_history b where a.kcdm=b.kcdm and a.zklb = b.zklb and b.ndm = ? and b.zklb = ? )