日期:2014-05-16 浏览次数:20748 次
--变量声明 -- .... -- 判断游标是否结束 declare v_curOver integer default 0; --声明游标 declare c_CCDZ cursor for select nvl(COL1, '') from TABLE1 where COL2=in_COL2; --声明异常处理,当游标结束时触发此异常(此句要放在最后声明) declare continue handler for not found set v_curOver=1; set v_curOver=0; open c_CCDZ; CCDZLoop: loop -- 注意:只有先fetch后才能有异常 fetch c_CCDZ into v_COL1; if v_curOver=1 then leave CCDZLoop; end if; update TABLE2 set COL11 = '01' where COL = v_COL1; end loop CCDZLoop; close c_CCDZ;
declare cursor1 cursor for select T1_COL2 from TABLE1 where T1_COL1 = in_COL1; select count(1) into v_NUM from TABLE1 where T1_COL1 = in_COL1; open cursor1; cursorLoop1: loop fetch cursor1 into v_COL2; if v_curOver=v_NUM then leave cursorLoop1; end if; --更新 update TABLE2 set COL2 = '01' where COL1 = v_COL2; set v_curOver = v_curOver + 1; end loop cursorLoop1; close cursor1;