oracle 批量插入時,如何去除重複資料____oracle

來源:互聯網
上載者:User

用儲存過程批量抽取一個視圖的資料,插入到一個建立的表,視圖資料有2.4億,昨天抽取到6千萬就卡住了,不知道什麼原因,想繼續執行這個預存程序,想請問加什麼條件來避免插入那些已經插入過的資料

視圖上有唯一性欄位  XH

儲存過程如下

create or replace procedure up_table as

type a is table of new_table%rowtype;

in_data a;

i number;

cursor c is select * from fcd_ci_gps@dblink;

begin

        open c;

        loop

        fetch c bulk collect into in_data limit 5000;

        forall i in 1..in_data.count

        insert into new_table values in_data(i);

        commit;

        exit when in_data.count=0;

        end loop;

        close c;
end;







最近剛做了一個你說的類似需求: 

我的業務需求是, 
從oracle資料庫中擷取資料,然後同步到sqlserver中。 

首先是配置兩個資料庫之間的串連設定。 
我是sqlserver 串連oracle 配置sqlserver的鏈路伺服器就OK。 

下面是預存程序的內容了: 

1. 建立暫存資料表。 

通過遠端連線,insert into 暫存資料表  select  遠端資料表  。 
擷取資料先到本地,。 

然後用 暫存資料表的資料,跟你本地業務表的資料進行對比。 
查詢不通的資料。 
Java代碼   -- (1) 遠程讀取NC需求計劃,分組摘要資料後,插入到暫存資料表 #tmp_pl_plan中。       set @InsertStrSQL = @InsertStrSQL+ @tmpStrSQl;       print(@InsertStrSQL) ;       exec(@InsertStrSQL);              select @tmpCont = count(1) from #tmp_pl_plan ;              -- state:0新增、1修改、2刪除       -- (2) 用本機資料與暫存資料表中的資料,進行對比,更新本地表中計劃數量與暫存資料表中不相等的記錄.                     update t set t.plnum  = a.plnum ,t.state = 1           from  #tmp_pl_plan a,NC_PL_PLAN t            where a.factorycode = t.factorycode and a.weldingdate = t.weldingdate           and a.divisions = t.divisions and a.zzmadeline = t.zzmadeline            and a.zzweldingwayCode  = t.zzweldingwayCode and a.zzmadelinetypeCode = t.zzmadelinetypeCode           and a.convertedcode = t.convertedcode and  a.ncfprocode = t.ncfprocode             and t.plnum != a.plnum             and t.weldingdate >=  @fbegdate and t.weldingdate <= @fenddate               -- (3) 對比資料,尋找本地表中存在,但是暫存資料表中不存在的記錄,然後修改本地表中的數量=0 ,state = 3 表示刪除           update t set t.plnum = 0 ,t.state = 2             from NC_PL_PLAN t           where t.weldingdate between  @fbegdate and @fenddate            and not exists (               select 1 from  #tmp_pl_plan a where a.factorycode = t.factorycode and a.weldingdate = t.weldingdate               and a.divisions = t.divisions and a.zzmadeline = t.zzmadeline                and a.zzweldingwayCode  = t.zzweldingwayCode and a.zzmadelinetypeCode = t.zzmadelinetypeCode               and a.convertedcode = t.convertedcode  and a.ncfprocode = t.ncfprocode                          );                 -- (4) 對比資料,新增暫存資料表中不存在於當前表的資料       --delete    NC_PL_PLAN;       insert into NC_PL_PLAN        select * from #tmp_pl_plan t       where t.weldingdate between  @fbegdate and @fenddate        and not exists (           select 1 from   NC_PL_PLAN a where a.factorycode = t.factorycode and a.weldingdate = t.weldingdate           and a.divisions = t.divisions and a.zzmadeline = t.zzmadeline            and a.zzweldingwayCode  = t.zzweldingwayCode and a.zzmadelinetypeCode = t.zzmadelinetypeCode           and a.convertedcode = t.convertedcode and a.ncfprocode = t.ncfprocode           and a.weldingdate >=  @fbegdate and a.weldingdate<= @fenddate        )       order by t.weldingdate desc ;  

最近剛做了一個你說的類似需求: 

我的業務需求是, 
從oracle資料庫中擷取資料,然後同步到sqlserver中。 

首先是配置兩個資料庫之間的串連設定。 
我是sqlserver 串連oracle 配置sqlserver的鏈路伺服器就OK。 

下面是預存程序的內容了: 

1. 建立暫存資料表。 

通過遠端連線,insert into 暫存資料表  select  遠端資料表  。 
擷取資料先到本地,。 

然後用 暫存資料表的資料,跟你本地業務表的資料進行對比。 
查詢不通的資料。 
Java代碼   -- (1) 遠程讀取NC需求計劃,分組摘要資料後,插入到暫存資料表 #tmp_pl_plan中。       set @InsertStrSQL = @InsertStrSQL+ @tmpStrSQl;       print(@InsertStrSQL) ;       exec(@InsertStrSQL);              select @tmpCont = count(1) from #tmp_pl_plan ;              -- state:0新增、1修改、2刪除       -- (2) 用本機資料與暫存資料表中的資料,進行對比,更新本地表中計劃數量與暫存資料表中不相等的記錄.                     update t set t.plnum  = a.plnum ,t.state = 1           from  #tmp_pl_plan a,NC_PL_PLAN t            where a.factorycode = t.factorycode and a.weldingdate = t.weldingdate           and a.divisions = t.divisions and a.zzmadeline = t.zzmadeline            and a.zzweldingwayCode  = t.zzweldingwayCode and a.zzmadelinetypeCode = t.zzmadelinetypeCode           and a.convertedcode = t.convertedcode and  a.ncfprocode = t.ncfprocode             and t.plnum != a.plnum             and t.weldingdate >=  @fbegdate and t.weldingdate <= @fenddate               -- (3) 對比資料,尋找本地表中存在,但是暫存資料表中不存在的記錄,然後修改本地表中的數量=0 ,state = 3 表示刪除           update t set t.plnum = 0 ,t.state = 2             from NC_PL_PLAN t           where t.weldingdate between  @fbegdate and @fenddate            and not exists (               select 1 from  #tmp_pl_plan a where a.factorycode = t.factorycode and a.weldingdate = t.weldingdate               and a.divisions = t.divisions and a.zzmadeline = t.zzmadeline                and a.zzweldingwayCode  = t.zzweldingwayCode and a.zzmadelinetypeCode = t.zzmadelinetypeCode               and a.convertedcode = t.convertedcode  and a.ncfprocode = t.ncfprocode      &

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.