oracle 存储过程

本文介绍了如何创建和调用一个名为'protest'的存储过程,该过程根据传入的日期更新table表中的数据,并通过循环和分批提交来优化性能。涵盖了基本的SQL编程和数据库操作知识。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

CREATE OR REPLACE PROCEDURE protest(vacdt in varchar) AS
  cursor cur_inst is
    select LOG_NO, AC_DT from table where AC_DT = vacdt;
  record     cur_inst%rowtype;
  i_count    int;
  i_allcount int;
BEGIN
  dbms_output.put_line('开始更新xxxx数据日期:' || vacdt || '-数据');
  i_count    := 0;
  i_allcount := 0;
  open cur_inst;
  loop
    fetch cur_inst
      into record;
    if cur_inst%notfound then
      --dbms_output.put_line('剩余条数:' ||i_count);
      commit;
      exit;
    end if;
    update table t
       set t.ac_dt_month = substr(t.ac_dt, 0, 6)
     where t.LOG_NO = record.LOG_NO
       and t.AC_DT = record.AC_DT;
    i_count    := i_count + 1;
    i_allcount := i_allcount + 1;
    if i_count >= 1000 then
      dbms_output.put_line('提交更新xxxx数据日期:' || vacdt || '-数据');
      i_count := 0;
      commit;
    end if;
  end loop;
  close cur_inst;
  dbms_output.put_line('结束更新xxxxx数据日期:' || vacdt || '-数据,数量:' || i_allcount);
END;

调用

--执行存储过程方法1::call
call protest('1111111');

--执行存储过程方法2:
begin
protest('111111');
end;

关于存储过程的基础知识的学习,可以参考下面 

https://blog.csdn.net/weixin_41968788/article/details/83659164

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值