oracle mysql 存储过程

一、Oracle

declare
  i number := 0;
   begin
   for rec in (SELECT ID
   FROM demo_tab d
   WHERE d.id = 2
  ) loop
 update demo2_tab set demo_column = 'xxx'  where id = rec.id;
  i := i + 1;
  if (mod(i, 1000) = 0) then
  commit;
 dbms_lock.sleep(1);
  end if;
  end loop;
  commit;
  end;

二、mysl

CREATE PROCEDURE  proc_demo()


BEGIN
            DECLARE i  INT DEFAULT 0;

            DECLARE done INT DEFAULT 0;

            DECLARE v_demo_code VARCHAR(100);

     DECLARE cur1 CURSOR FOR SELECT demo_code from demo_tab ;  

     DECLARE CONTINUE HANDLER FOR NOT FOUND SET done=1; 

  (注意:当游标查询的数据量非常大时,需要如下方式加大缓存。)

    set read_buffer_size=104857600;
  set sort_buffer_size=104857600;

  set read_rnd_buffer_size=209715200;



     OPEN cur1;  

     emp_loop: LOOP  

         FETCH cur1 INTO  v_demo_code;  

                                SET autocommit=0;

                               update demo2_tab set xx_column = 'xxxx'  where demo_code = v_demo_code;

                               set i = i + 1;

                               IF mod(i,5000) = 0

                                        then commit;

                                 set i = 0;

                               END IF;

         IF done=1 THEN  

                                  commit;

             LEAVE emp_loop;  

         END IF;  

     END LOOP emp_loop;  

     commit;

     CLOSE cur1;  

END

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值