














前面所说,在这里有三个表的约束,起初考虑用游标将临时表user_temp中的数据逐条遍历处理
但是总听人说游标耗资源,而且数据量较多时应避免
所以还是不采用(人云亦云。。。)
CREATE OR REPLACE Procedure due_ImportArrearsUser
(
p_policyId In ics001.user_push_times.policyid%Type,
p_result Out Integer
--- -1001,删除临时表中在白名单中存在的记录时出错
--- -1002,删除临时表中与due_user表中重复的记录出错
--- -1003,将临时表中的数据插入due_user表出错
--- -1004,临时表中在user_push_time表中已有的记录,更新出错
--- -1005,临时表中不存在于user_push_time表中的记录,插入出错
--- -1006,清空临时表数据出错
--- 0,成功
)
Is
v_userCount Integer;
Begin
-----删除临时表中在白名单中存在的记录------
Delete From due_user_temp a
Where Exists( Select 1
From due_whiteuser b
Where a.username = b.username And a.province = b.province And a.city = b.city );
-----删除临时表中与due_user表中重复的记录---
Delete From due_user_temp a
Where Exists( Select 1
From due_user b
Where a.username = b.username And a.province = b.province And a.city = b.city );
-----将临时表中的数据插入due_user表----
Insert Into due_user
Select * From due_user_temp;
----根据临时表中的数据,update或insert ics001.user_push_times表---
----临时表中在user_push_time表中已有的记录,更新-----
Update
(Select push.validflag, push.pushtimes,push.pushdaytimes, push.lastpushedtime
From ics001.user_push_times push, due_user_temp temp
Where push.username = temp.username And push.policyid = p_policyId)
Set validflag = 1, pushtimes = 0, pushdaytimes = 0, lastpushedtime = 0;
---临时表中不存在于user_push_time表中的记录,插入----
INSERT INTO ics001.user_push_times(username,ip,policyid,pushtimes,pushdaytimes,validflag,fileId,createtime)
Select temp.username, 0, p_policyId, 0, 0, 1, 999997, Sysdate
From ics001.user_push_times push, due_user_temp temp
Where temp.username = push.username(+) And push.username Is Null;
Select Count( * ) Into v_userCount From due_user_temp;
If(v_userCount > 0 ) Then
Begin
Delete From due_user_temp;
If Sql%Notfound Then
p_result := -1006;
Return;
End If;
End;
End If;
p_result := v_userCount;
Return;
End due_importarrearsuser;
呵呵,这个procedure写了我快一天。。。。实在是不熟oracle,惭愧,要去闭关一段
肯定还是有改善的余地的,不过偶能力范围内是想不出了。
不知道游标方式是否真的会很耗性能?
大大们如果觉得还有哪里可以提高的地方
恳请赐教。。。
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。