前一阵子在实施中发现问题,需要当时进行修改,而因为数据库中数据是真实数据,不能进行修改,否则会出大纰漏吧,于是添加测试数据来方便修改,而单个添加效率太低下了,所以解决的办法就是以真实的数据为模板增添新方便删除的数据即可,就像将2014年的数据复制一份只将年份进行修改,删除的时候讲这个不存在的年份数据删除即可。
相信大家很容易会想到这个方法,也很容易做出答案,举个例子:
看这个表,因为主键中都是以当年年份开头的,同时年度也是当年年份,这样我们就可以进行添加修改:
假使说这个表格存在如下列:
btfid、production、code、retrieveid、location、tobaccostation、plantvillage、cooperation、tobaccotechnician、eastlong、eastlat、southlong、southlat、westlong、westlat、northlong、northlat、amsl、totalarea
那样我们可以可以这样写:
insert into
arc_basictobaccofield
select '2016' || substr(btfid, 5),
'2016',
code,
retrieveid,
location,
tobaccostation,
plantvillage,
cooperation,
tobaccotechnician,
eastlong,
eastlat,
southlong,
southlat,
westlong,
westlat,
northlong,
northlat,
amsl,
totalarea
from arc_basictobaccofield
where tobaccostation = '37030405C'
and productionyear = 2015答案是肯定的,这样我们倒过来思考下,我们只需要修改两列而已,那我们就把所有数据取出来,将这两列数据修改之后进行插入不就可以了么,我们来写下看:
首先我们来创建一个临时表:
create table arc_basictobaccofield1 as select * from arc_basictobaccofield where tobaccostation='37030405C' and productionyear=2015
update arc_basictobaccofield1 set productionyear=2015 update arc_basictobaccofield1 set btfid ='2015'||substr(btfid,5)
insert into arc_basictobaccofield select * from arc_basictobaccofield1
drop table arc_basictobaccofield1
原文地址:http://blog.csdn.net/marsmile_tbo/article/details/42966011