最近生产库反应出一个问题,某张表的主键ID并没有按照原计划的期望增加,而是间歇性跳号,每次跳2万多,经过研究发现是某个同步过程的merge into引起的,具体语句如下
merge into t_ifi_invest_ordplan_detail a
using (select f.client_id,
f.fund_account,
f.fund_code,
f.fund_company,
f.balance,
f.allotno,
f.en_fund_date,
f.start_date,
f.end_date,
s.cpid,
s.cpmc
from t_ifi_ofrationtime f
left join t_ifi_singlefund_info s
on f.fund_code = s.cpdm
where f.deal_flag = ‘0’ –过滤当日取消操作
) t on (a.allotno = t.allotno)
when not matched then
insert
(a.plan_detail_id,
a.plan_id,
a.client_id,
a.fund_account,
a.fund_code,
a.fund_company,
a.fix_invest,
a.allotno,
a.fund_id,
a.plan_name,
a.openacc_flag)
values
(seq_ifi_invest_ordplan_detail.nextval,
seq_ifi_invest_ordplan.nextval,
t.client_id,
t.fund_account,
t.fund_code,
t.fund_company,
t.balance,
t.allotno,
t.cpid,
t.cpmc || ‘普通定投’ || seq_ifi_invest_ordplan.currval,
‘1’)
经过实验发现,虽然每次同步新增的数据不多,但是序列总是跳一个波段,而跳的间隔数刚好是本次using里面查到的数据总量,很是奇怪。
解决方法:单独写个获取序列的方法,将merge into 里面的seq_ifi_invest_ordplan_detail.nextval换成用方法获取序列,再次测试,问题解决。究竟原因目前还不得知,有知道的可以留言告知下,谢谢。