我们有一个“合并”脚本,用于为客户分配代码。目前,该脚本通过查看暂存表中的客户并分配未使用的代码来工作。这些代码被标记为已使用,并将带有代码的暂存记录加载到生产表中。暂存表被清除,一切都很好。
不幸的是,我们现在正在处理更大的数据集(包括客户和代码),而且该过程运行时间太长了。我希望这里的精英社区可以查看这里的代码,并提供改进或另一种解决问题的方法。
谢谢!
编辑 - 忘记提到在这个检查的部分的原因是暂存表是“活动的”,在脚本运行期间可能会有记录进入其中。
不幸的是,我们现在正在处理更大的数据集(包括客户和代码),而且该过程运行时间太长了。我希望这里的精英社区可以查看这里的代码,并提供改进或另一种解决问题的方法。
谢谢!
编辑 - 忘记提到在这个检查的部分的原因是暂存表是“活动的”,在脚本运行期间可能会有记录进入其中。
whenever sqlerror exit 1
-- stagingTable: TAB_000000003134
-- codeTable: TAB_000000003135
-- masterTable: TAB_000000003133
-- dedupe staging table
delete from TAB_000000003134 a
where ROWID > (
select min(rowid)
from TAB_000000003134 b
where a.cust_id = b.cust_id
);
commit;
delete from TAB_000000003134
where cust_id is null;
commit;
-- set row num on staging table
update TAB_000000003134
set row_num = rownum;
commit;
-- reset row nums on code table
update TAB_000000003135
set row_num = NULL;
commit;
-- assign row nums to codes
update TAB_000000003135
set row_num = rownum
where dateassigned is null
and active = 1;
commit;
-- attach codes to staging table
update TAB_000000003134 d
set (CODE1, CODE2) =
(
select CODE1, CODE2
from TAB_000000003135 c
where d.row_num = c.row_num
);
commit;
-- mark used codes compared to template
update TAB_000000003135 c
set dateassigned = sysdate, assignedto = (select cust_id from TAB_000000003134 d where c.CODE1 = d.CODE1)
where exists (select 'x' from TAB_000000003134 d where c.CODE1 = d.CODE1);
commit;
-- clear and copy data to master
truncate table TAB_000000003133;
insert into TAB_000000003133 (
<custmomer fields>, code1, code2, TIMESTAMP_
)
select <custmomer fields>, CODE1, CODE2,SYSDATE
from TAB_000000003134;
commit;
-- remove any staging records with code numbers
delete from TAB_000000003134
where CODE1 is not NULL;
commit;
quit