將一個資料庫中的資料匯入另一個資料庫(DB2)

來源:互聯網
上載者:User

標籤:

將一個資料庫中的資料匯入另一個資料庫(DB2)

我這裡舉得例子是使用的DB2資料庫,其他資料庫思路也是這樣啦!

1、從db2 資料庫中將表中的資料匯入本地的excel中
export to d:\mytest.xls of del modified by nochardel coldel0x09 select * from IOUT_BUSI_YWDJMX_TEMP
2、在需要匯入的資料庫建立一個暫存資料表
--建立暫存資料表CREATE TABLE NBADV.l_hzcitywa(fhcode varchar(20),dhcode varchar(20),away DECIMAL(19, 4))DATA CAPTURE NONEIN [email protected]ALTER TABLE NBADV.l_hzcitywaLOCKSIZE ROWAPPEND OFFNOT [email protected]
3、將excel另存新檔csv格式的檔案,匯入到資料庫的暫存資料表中
--將資料匯入暫存資料表import from "D:\hz.csv" OF DEL INSERT INTO [email protected]
4、對資料進行處理
--查出重複的資料select distinct a.DELI_UNIT_CD,c.fhcode,a.ARRI_UNIT_CD,c.dhcode,count(c.away) from ST_I_STD_MILEAGE a inner join nbadv.l_hzcitywa c on a.DELI_CITY_NM=c.fhcode and a.ARRI_CITY_NM=c.dhcodegroup by a.DELI_UNIT_CD,c.fhcode,a.ARRI_UNIT_CD,c.dhcodehaving count(*)>1--刪除掉重複的資料delete from nbadv.l_hzcitywa where dhcode in (‘北京‘,‘東莞‘,‘拉薩‘,‘天水‘,‘酒泉‘,‘平涼‘,‘慶陽‘,‘銅川‘,‘鹹陽‘,‘煙台‘)@
5、處理後的資料通過db2預存程序將所需要的資料更新到第二個資料庫的表中,這裡關鍵是找到暫存資料表與需要更新資料的表中的關聯關係;
--建立預存程序,更新合約裡程drop procedure [email protected]create procedure L_getcityway(in v_personId    int)language sqldynamic result sets 0begindeclare sqlcode int;declare sqlstate char(5);declare v_errcode int default 0;--更新合約裡程merge into ST_I_TRANS_MILEAGE ausing (select distinct a.DELI_UNIT_CD,c.fhcode,a.ARRI_UNIT_CD,c.dhcode,c.away from ST_I_STD_MILEAGE a inner join nbadv.l_hzcitywa c on a.DELI_CITY_NM=c.fhcode and a.ARRI_CITY_NM=c.dhcode and c.fhcode= ‘渭南‘)bon a.DELI_STORE_CD=b.DELI_UNIT_CD and a.ARRI_STORE_CD=b.ARRI_UNIT_CDwhen matched then update set a.ACTUAL_MILEAGE=b.away;--計算差異update ST_I_TRANS_MILEAGE set DIFFERENCE=(ACTUAL_MILEAGE-STD_MILEAGE)*100.000000/STD_MILEAGE where DELI_STORE_CD=2061000101 and STD_MILEAGE is not null and STD_MILEAGE<>0;--更新備忘update ST_I_TRANS_MILEAGE set REMARK=‘無‘ where DIFFERENCE>10 and DELI_STORE_CD in (‘2061000101‘,‘2061000102‘,‘2061000103‘,‘2061000104‘,‘2061000105‘);return v_errcode;end@

到此,已經實現從第一個資料庫的表中的資料更新到第二個資料庫中了;

將一個資料庫中的資料匯入另一個資料庫(DB2)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.