oracle 存储过程循环打开游标数据处理
2017-07-24 14:12:42
SQL内容:
1.一次性检索 100000 条数据。
2. 1000 条提交一次。
3.超过 100000 万条,重新打开游标,重新检索。
pl/sql内容如下:
1 CREATE OR REPLACE PROCEDURE P_MDF_TEST ( branchno1 in varchar ) 2 AS 3 cursor cur_inst is select plcno from t1test where 4 branch in ( select branchcode from t_test start with branchcode =branchno1 connect by prior branchcode = supercode ) 5 and primprdcode in ( '123', '234') 6 and ( InsExprtDate <> date '9999-12-31' or InsExprtDate is null ); 7 record cur_inst%rowtype; 8 i_count int; 9 iFlag int ; 10 -- v_end varchar2(30); 时间 11 BEGIN 12 dbms_output.put_line('开始执行'); 13 iFlag :=1; 14 loop 15 if iFlag = 0 then 16 exit; 17 end if; 18 i_count:=0; 19 open cur_inst; 20 if cur_inst%isopen then 21 loop 22 fetch cur_inst into record; 23 if cur_inst%notfound then 24 iFlag:=0; 25 exit; 26 end if ; 27 update t1test set InsExprtDate =date '9999-12-31' where plcno=record.plcno; 28 update t2test set InsExprtDate =date '9999-12-31' where plcno=record.plcno; 29 -- dbms_output.put_line(record.plcno); 30 i_count := i_count + 1; 31 if i_count >=1000 then 32 -- dbms_output.put_line(i_count); 33 -- select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') into v_end from dual; 34 -- dbms_output.put_line(v_end); 35 i_count:=0; 36 commit; 37 end if ; 38 if cur_inst%ROWCOUNT >=100000 then 39 -- dbms_output.put_line('进来了'); 40 -- dbms_output.put_line(cur_inst%ROWCOUNT); 41 exit ; 42 end if ; 43 end loop; 44 commit; 45 close cur_inst; 46 end if; 47 end loop; 48 dbms_output.put_line('执行结束'); 49 END;
新建测试窗口,执行以下内容:
begin -- Call the procedure p_mdf_test(branchno1 => '122'); end;
一路走来,有点累,有点醉...(如需转载,请注明出处)
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通