惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
博客园 - 司徒正美
宝玉的分享
宝玉的分享
阮一峰的网络日志
阮一峰的网络日志
The Cloudflare Blog
月光博客
月光博客
博客园 - 【当耐特】
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园 - 三生石上(FineUI控件)
博客园 - 聂微东
小众软件
小众软件
Hugging Face - Blog
Hugging Face - Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
Apple Machine Learning Research
Apple Machine Learning Research
V
V2EX
Jina AI
Jina AI
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
罗磊的独立博客
雷峰网
雷峰网
博客园 - 叶小钗
量子位
IT之家
IT之家

博客园 - ivanking

(转载)常用格式转换 smil教程(转载) Nhibernate之初体验(一) 构建安全的Web Service Getting start with nhibernate) CrystalReport开发常见错误总结 SQL Server日志文件的相关处理(转帖) 常用正则表达式收集 - ivanking - 博客园 Nov 2th 2005 Aug 13th 2005 Sep 5th 2005 ---- Sep 12th 2005 Aug 31th 2005 Aug 26th 2005 优化较大数据量的处理效率的收获(总结,疑问) 优化较大数据量的处理效率的收获(优化思路) 优化较大数据量的处理效率的收获(寻找瓶颈) 优化较大数据量的处理效率的收获(前言) 在域控制器上vs.net 2003无法调试的解决办法 几个js验证函数 - ivanking - 博客园
优化较大数据量的处理效率的收获(sql性能优化)
ivanking · 2005-08-08 · via 博客园 - ivanking

前面所说,在这里有三个表的约束,起初考虑用游标将临时表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 ExistsSelect 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 ExistsSelect 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, 001999997, 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,惭愧,要去闭关一段
肯定还是有改善的余地的,不过偶能力范围内是想不出了。

不知道游标方式是否真的会很耗性能?
大大们如果觉得还有哪里可以提高的地方
恳请赐教。。。