oracle去除表中重复数据的sql语句与merge into用法

1、从A库中去重后倒入B库中
Insert into tdsc.T_CBGY (select * from (select distinct * from tdly.T_CBGY t))
2、删除表中重复数据
DELETE from t_cbgy
WHERE (cbgy_guid) IN ( SELECT cbgy_guid FROM t_cbgy GROUP BY cbgy_guid HAVING COUNT(cbgy_guid) > 1) AND ROWID NOT IN (SELECT MIN(ROWID) FROM t_cbgy GROUP BY cbgy_guid HAVING COUNT(*) > 1);
3、删除表中重复数据DELETE from T_GYGG
WHERE (gygg_guid) IN (
SELECT gygg_guid FROM
T_GYGG GROUP BY gygg_guid
HAVING COUNT(gygg_guid) > 1)
AND ROWID NOT IN (SELECT MIN(ROWID)
FROM T_GYGG GROUP BY gygg_guid
HAVING COUNT(*) > 1);
4、以上删除执行效率在10万条以上效率低,执行数小时以上没有结果
用以下语句能提高执行效率

delete from t_gdxm where
rowid in (select rid
from (select rowid rid,row_number()
over(partition by gd_guid
order by rowid)
rn from t_gdxm) where rn <> 1 );
5、执行差分处理merge into
merge into dtjc.t_gdxm new_gdxm
using tdly.t_gdxm temp_gdxm
on (new_gdxm.gd_guid = temp_gdxm.gd_guid)
when matched then
update set
new_gdxm.zd_guid=temp_gdxm.zd_guid,
new_gdxm.xzq_dm=temp_gdxm.xzq_dm,
new_gdxm.bh=temp_gdxm.bh,
new_gdxm.dz_ba_bh=temp_gdxm.dz_ba_bh,
new_gdxm.td_zl=temp_gdxm.td_zl,
new_gdxm.zd_bh=temp_gdxm.zd_bh,
new_gdxm.xm_mc=temp_gdxm.xm_mc,
new_gdxm.xm_xh=temp_gdxm.xm_xh,
new_gdxm.tzzt_xz=temp_gdxm.tzzt_xz,
new_gdxm.hy_fl=temp_gdxm.hy_fl,
new_gdxm.td_jb=temp_gdxm.td_jb,
new_gdxm.gd_zmj=temp_gdxm.gd_zmj,
new_gdxm.gy_fs=temp_gdxm.gy_fs,
new_gdxm.gy_mj=temp_gdxm.gy_mj,
new_gdxm.xz_mj=temp_gdxm.xz_mj,
new_gdxm.pc_mj=temp_gdxm.pc_mj,
new_gdxm.gy_wld_mj=temp_gdxm.gy_wld_mj,
new_gdxm.cl_mj=temp_gdxm.cl_mj,
new_gdxm.cl_xzcr_mj=temp_gdxm.cl_xzcr_mj,
new_gdxm.cl_gbxzcr_mj=temp_gdxm.cl_gbxzcr_mj,
new_gdxm.cl_qt_mj=temp_gdxm.cl_qt_mj,
new_gdxm.cl_xq=temp_gdxm.cl_xq,
new_gdxm.cr_nx=temp_gdxm.cr_nx,
new_gdxm.yt_sm=temp_gdxm.yt_sm,
new_gdxm.qd_rq=temp_gdxm.qd_rq,
new_gdxm.jd_sj=temp_gdxm.jd_sj,
new_gdxm.dg_sj=temp_gdxm.dg_sj,
new_gdxm.jg_sj=temp_gdxm.jg_sj,
new_gdxm.bg_jd_sj=temp_gdxm.bg_jd_sj,
new_gdxm.bg_dg_sj=temp_gdxm.bg_dg_sj,
new_gdxm.bg_jg_sj=temp_gdxm.bg_jg_sj,
new_gdxm.sj_jd_sj=temp_gdxm.sj_jd_sj,
new_gdxm.sj_dg_sj=temp_gdxm.sj_dg_sj,
new_gdxm.sj_jg_sj=temp_gdxm.sj_jg_sj,
new_gdxm.pz_wh=temp_gdxm.pz_wh,
new_gdxm.pz_rq=temp_gdxm.pz_rq,
new_gdxm.pz_jg=temp_gdxm.pz_jg,
new_gdxm.kfjs_qx=temp_gdxm.kfjs_qx,
new_gdxm.je=temp_gdxm.je,
new_gdxm.gdzc_tze=temp_gdxm.gdzc_tze,
new_gdxm.tz_qd=temp_gdxm.tz_qd,
new_gdxm.zt_jz_xz=temp_gdxm.zt_jz_xz,
new_gdxm.fs_jz_xz=temp_gdxm.fs_jz_xz,
new_gdxm.jz_mj=temp_gdxm.jz_mj,
new_gdxm.min_jz_md=temp_gdxm.min_jz_md,
new_gdxm.min_jz_md_tag=temp_gdxm.min_jz_md_tag,
new_gdxm.max_jz_md=temp_gdxm.max_jz_md,
new_gdxm.max_jz_md_tag=temp_gdxm.max_jz_md_tag,
new_gdxm.min_rjl=temp_gdxm.min_rjl,
new_gdxm.min_rjl_tag=temp_gdxm.min_rjl_tag,
new_gdxm.max_rjl=temp_gdxm.max_rjl,
new_gdxm.max_rjl_tag=temp_gdxm.max_rjl_tag,
new_gdxm.min_lhl=temp_gdxm.min_lhl,
new_gdxm.min_lhl_tag=temp_gdxm.min_lhl_tag,
new_gdxm.max_lhl=temp_gdxm.max_lhl,
new_gdxm.max_lhl_tag=temp_gdxm.max_lhl_tag,
new_gdxm.min_jz_gd=temp_gdxm.min_jz_gd,
new_gdxm.min_jz_gd_tag=temp_gdxm.min_jz_gd_tag,
new_gdxm.max_jz_gd=temp_gdxm.max_jz_gd,
new_gdxm.max_jz_gd_tag=temp_gdxm.max_jz_gd_tag,
new_gdxm.qt_td_yq=temp_gdxm.qt_td_yq,
new_gdxm.kftz_ze=temp_gdxm.kftz_ze,
new_gdxm.zd_sz_qy=temp_gdxm.zd_sz_qy,
new_gdxm.ht_lx=temp_gdxm.ht_lx,
new_gdxm.paraid=temp_gdxm.paraid,
new_gdxm.kfly_bz=temp_gdxm.kfly_bz,
new_gdxm.wkfly_yy=temp_gdxm.wkfly_yy,
new_gdxm.sf_sh=temp_gdxm.sf_sh,
new_gdxm.xz_zt=temp_gdxm.xz_zt,
new_gdxm.qy_ss_lx=temp_gdxm.qy_ss_lx,
new_gdxm.lsxz_zt=temp_gdxm.lsxz_zt,
new_gdxm.create_user=temp_gdxm.create_user,
new_gdxm.create_date=temp_gdxm.create_date,
new_gdxm.delete_date=temp_gdxm.delete_date,
new_gdxm.modify_date=temp_gdxm.modify_date,
new_gdxm.ch_sj=temp_gdxm.ch_sj,
new_gdxm.tb_zt=temp_gdxm.tb_zt,
new_gdxm.sb_cs=temp_gdxm.sb_cs,
new_gdxm.sbr=temp_gdxm.sbr,
new_gdxm.sb_sj=temp_gdxm.sb_sj,
new_gdxm.sb_xzq=temp_gdxm.sb_xzq,
new_gdxm.xm_cj=temp_gdxm.xm_cj,
new_gdxm.xm_zt=temp_gdxm.xm_zt,
new_gdxm.old_gd_guid=temp_gdxm.old_gd_guid,
new_gdxm.wl_bz=temp_gdxm.wl_bz,
new_gdxm.bz=temp_gdxm.bz,
new_gdxm.srr=temp_gdxm.srr,
new_gdxm.cyzc_wh=temp_gdxm.cyzc_wh,
new_gdxm.w_cyzc_sm=temp_gdxm.w_cyzc_sm,
new_gdxm.gjbg_bah=temp_gdxm.gjbg_bah,
new_gdxm.have_bah=temp_gdxm.have_bah,
new_gdxm.td_yt=temp_gdxm.td_yt
when not matched then
insert values(
temp_gdxm.gd_guid,
temp_gdxm.zd_guid,
temp_gdxm.xzq_dm,
temp_gdxm.bh,
temp_gdxm.dz_ba_bh,
temp_gdxm.td_zl,
temp_gdxm.zd_bh,
temp_gdxm.xm_mc,
temp_gdxm.xm_xh,
temp_gdxm.tzzt_xz,
temp_gdxm.hy_fl,
temp_gdxm.td_jb,
temp_gdxm.gd_zmj,
temp_gdxm.gy_fs,
temp_gdxm.gy_mj,
temp_gdxm.xz_mj,
temp_gdxm.pc_mj,
temp_gdxm.gy_wld_mj,
temp_gdxm.cl_mj,
temp_gdxm.cl_xzcr_mj,
temp_gdxm.cl_gbxzcr_mj,
temp_gdxm.cl_qt_mj,
temp_gdxm.cl_xq,
temp_gdxm.cr_nx,
temp_gdxm.yt_sm,
temp_gdxm.qd_rq,
temp_gdxm.jd_sj,
temp_gdxm.dg_sj,
temp_gdxm.jg_sj,
temp_gdxm.bg_jd_sj,
temp_gdxm.bg_dg_sj,
temp_gdxm.bg_jg_sj,
temp_gdxm.sj_jd_sj,
temp_gdxm.sj_dg_sj,
temp_gdxm.sj_jg_sj,
temp_gdxm.pz_wh,
temp_gdxm.pz_rq,
temp_gdxm.pz_jg,
temp_gdxm.kfjs_qx,
temp_gdxm.je,
temp_gdxm.gdzc_tze,
temp_gdxm.tz_qd,
temp_gdxm.zt_jz_xz,
temp_gdxm.fs_jz_xz,
temp_gdxm.jz_mj,
temp_gdxm.min_jz_md,
temp_gdxm.min_jz_md_tag,
temp_gdxm.max_jz_md,
temp_gdxm.max_jz_md_tag,
temp_gdxm.min_rjl,
temp_gdxm.min_rjl_tag,
temp_gdxm.max_rjl,
temp_gdxm.max_rjl_tag,
temp_gdxm.min_lhl,
temp_gdxm.min_lhl_tag,
temp_gdxm.max_lhl,
temp_gdxm.max_lhl_tag,
temp_gdxm.min_jz_gd,
temp_gdxm.min_jz_gd_tag,
temp_gdxm.max_jz_gd,
temp_gdxm.max_jz_gd_tag,
temp_gdxm.qt_td_yq,
temp_gdxm.kftz_ze,
temp_gdxm.zd_sz_qy,
temp_gdxm.ht_lx,
temp_gdxm.paraid,
temp_gdxm.kfly_bz,
temp_gdxm.wkfly_yy,
temp_gdxm.sf_sh,
temp_gdxm.xz_zt,
temp_gdxm.qy_ss_lx,
temp_gdxm.lsxz_zt,
temp_gdxm.create_user,
temp_gdxm.create_date,
temp_gdxm.delete_date,
temp_gdxm.modify_date,
temp_gdxm.ch_sj,
temp_gdxm.tb_zt,
temp_gdxm.sb_cs,
temp_gdxm.sbr,
temp_gdxm.sb_sj,
temp_gdxm.sb_xzq,
temp_gdxm.xm_cj,
temp_gdxm.xm_zt,
temp_gdxm.old_gd_guid,
temp_gdxm.wl_bz,
temp_gdxm.bz,
temp_gdxm.srr,
temp_gdxm.cyzc_wh,
temp_gdxm.w_cyzc_sm,
temp_gdxm.gjbg_bah,
temp_gdxm.have_bah,
temp_gdxm.td_yt
)

你可能感兴趣的:(oracle)