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

推荐订阅源

T
Threatpost
S
Securelist
D
Darknet – Hacking Tools, Hacker News & Cyber Security
T
Threat Research - Cisco Blogs
C
Cyber Attacks, Cyber Crime and Cyber Security
T
Tenable Blog
I
Intezer
G
GRAHAM CLULEY
Spread Privacy
Spread Privacy
T
Tor Project blog
V
Vulnerabilities – Threatpost
NISL@THU
NISL@THU
L
Lohrmann on Cybersecurity
Schneier on Security
Schneier on Security
MyScale Blog
MyScale Blog
The GitHub Blog
The GitHub Blog
S
Security @ Cisco Blogs
The Register - Security
The Register - Security
酷 壳 – CoolShell
酷 壳 – CoolShell
B
Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
L
LangChain Blog
人人都是产品经理
人人都是产品经理
T
Tailwind CSS Blog
MongoDB | Blog
MongoDB | Blog
小众软件
小众软件
The Hacker News
The Hacker News
Google DeepMind News
Google DeepMind News
Microsoft Security Blog
Microsoft Security Blog
U
Unit 42
博客园 - 叶小钗
Attack and Defense Labs
Attack and Defense Labs
Webroot Blog
Webroot Blog
大猫的无限游戏
大猫的无限游戏
Apple Machine Learning Research
Apple Machine Learning Research
H
Hackread – Cybersecurity News, Data Breaches, AI and More
aimingoo的专栏
aimingoo的专栏
T
Troy Hunt's Blog
V
Visual Studio Blog
P
Proofpoint News Feed
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
A
Arctic Wolf
T
The Exploit Database - CXSecurity.com
宝玉的分享
宝玉的分享
Vercel News
Vercel News
D
DataBreaches.Net
P
Palo Alto Networks Blog
AI
AI
Simon Willison's Weblog
Simon Willison's Weblog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC

博客园 - kwame

CXX0017错误的解决办法 基础知识--is & as 的区别 - kwame 基础知识--变量和常量 - kwame - 博客园 基础知识--Boxing & unBoxing 基础知识--值类型和引用类型 用Visual C#创建Windows服务程序 (转)用C语言编写Windows服务程序的五个步骤 昨天的事今天来写也叫昨天的日记吧?? 我是个被窥视狂? 一个馒头和一个*六*合*彩*网站引发的血案 *六*合*彩*网站也能做成这样不容易呀! 取得一段汉语的每个字的首字母 写入、读取 cookie 无聊顺便复习了下前面学的东西! 网页效果集合(小技巧) C#.net word 受控编程系列1-向word中插入图片 安装和部署企业程序库(Installation and Deployment of Enterprise Library) OA需要分析3 OA需求分析2 OA需求分析1
Oracle中隐式游标和显式游标的教训[同事的经历]
kwame · 2006-03-01 · via 博客园 - kwame

转自:http://www.cnblogs.com/PiedPiper/archive/2006/02/28/339919.html

一直以为以下这种语句(执行一)就是隐式游标,跟显式定义游标(执行二)运行速度差不了多少。为方便简单起见,我通常都是用执行一的方式来写循环操作,数据量较小没有觉得有什么,只到有一天,一个海量数据的更新运行了一晚上都没出来结果,才知道自己犯了多大的错误:
执行一:
begin
    for c in (
     select ca.org_code, m.material_code, sum(cd.num) ammount
             from mas_admin.ASC_STOCK_CHANGE_BILL c
         join mas_admin.ASC_STOCK_CHANGE_DETAIL cd on c.STOCK_CHANGE_BILL_ID =
                                     cd.STOCK_CHANGE_BILL_ID
          join mas_admin.asc_materiel m on m.materiel_id = cd.MATERIAL_ID --物料表
          join mas_admin.asc_stock s on s.STOCK_ID = c.STOCK_ID
          join mas_admin.asc_agent ca on ca.ORG_ID = s.org_id
           where c.ENABLE_FLAG = 'Y'
            and s.STOCK_TYPE_ID = 1
             and c.BILL_STATE = 3
            and substr(ca.org_code, 1, 3) <> 'BAK'
           and c.STOCK_CHANGE_REASON_ID=3 -- 3=系统错误
           group by ca.org_code, m.material_code
  ) loop
       update asc_ca_stock_good_usable
    set ADJUST_NUM_ERROR=c.ammount
    where ORG_CODE=c.org_code and MATERIAL_CODE=c.MATERIAL_CODE and action_date=curr_date;
      end loop;
    commit; 
    end;
执行二:
 declare
    var_org_code varchar2(50);
    var_material_code varchar2(50);
    var_ammount number;
    cursor c is
       select ca.org_code, m.material_code, sum(cd.num) ammount
             from mas_admin.ASC_STOCK_CHANGE_BILL c
         join mas_admin.ASC_STOCK_CHANGE_DETAIL cd on c.STOCK_CHANGE_BILL_ID =
                                     cd.STOCK_CHANGE_BILL_ID
          join mas_admin.asc_materiel m on m.materiel_id = cd.MATERIAL_ID --物料表
          join mas_admin.asc_stock s on s.STOCK_ID = c.STOCK_ID
          join mas_admin.asc_agent ca on ca.ORG_ID = s.org_id
           where c.ENABLE_FLAG = 'Y'
            and s.STOCK_TYPE_ID = 1
             and c.BILL_STATE = 3
            and substr(ca.org_code, 1, 3) <> 'BAK'
           and c.STOCK_CHANGE_REASON_ID=3 -- 3=系统错误
           group by ca.org_code, m.material_code;
begin
    open c;
    loop
       fetch c into var_org_code,var_material_code,var_ammount;
       exit when c%notfound;
       update asc_ca_stock_good_usable
    set ADJUST_NUM_ERROR=var_ammount
    where ORG_CODE=var_org_code and MATERIAL_CODE=var_material_code and action_date=trunc(sysdate);
      commit;
      end loop;    
    end;

执行一10多分钟算不完,执行二只需0.2秒