我们有一个'merge'脚本,用于为客户分配代码。目前,它的工作原理是在临时表中查看客户并为其分配未使用的代码。这些代码被标记为已使用,并且带有代码的分阶段记录被加载到生产表中。临时表被清除,生命很好。
不幸的是,我们现在正在使用更大的数据集(包括客户和代码),并且该流程需要花费很长时间才能运行。我希望这里的精彩社区可以在这里查看代码,并提供改进或其他方式来解决问题。
提前致谢!
编辑 - 忘记提及部分检查的部分原因是临时表是“活的”并且可以在脚本运行期间输入记录。
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
答案 0 :(得分:1)
答案 1 :(得分:0)
COMMIT
。这不仅仅是性能,而是因为在脚本结束之前数据不是一致的状态。(事实证明,在Oracle中提交频率可能较低performance benefits,但您主要关心的是保持一致性)