时间:2021-07-01 10:21:17 帮助过:3人阅读
--创建临时表 CREATE TABLE NBADV.l_hzcitywa ( fhcode varchar(20), dhcode varchar(20), away DECIMAL(19, 4) ) DATA CAPTURE NONE IN USERSPACE1@ ALTER TABLE NBADV.l_hzcitywa LOCKSIZE ROW APPEND OFF NOT VOLATILE@
--将数据导入临时表 import from "D:\hz.csv" OF DEL INSERT INTO nbadv.l_hzcitywa@
--查出重复的数据 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.dhcode group by a.DELI_UNIT_CD,c.fhcode,a.ARRI_UNIT_CD,c.dhcode having count(*)>1 --删除掉重复的数据 delete from nbadv.l_hzcitywa where dhcode in (‘北京‘,‘东莞‘,‘拉萨‘,‘天水‘,‘酒泉‘,‘平凉‘,‘庆阳‘,‘铜川‘,‘咸阳‘,‘烟台‘)@
--创建存储过程,更新合同里程 drop procedure L_getcityway@ create procedure L_getcityway( in v_personId int ) language sql dynamic result sets 0 begin declare sqlcode int; declare sqlstate char(5); declare v_errcode int default 0; --更新合同里程 merge into ST_I_TRANS_MILEAGE a using ( 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= ‘渭南‘ )b on a.DELI_STORE_CD=b.DELI_UNIT_CD and a.ARRI_STORE_CD=b.ARRI_UNIT_CD when 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)
标签: