sábado, 29 de agosto de 2015

Oracle - Cursor




Como é montado um cursor ?

declare
   i number := 0;
   cursor s1 is
      SELECT * FROM tab1 WHERE col1 = 'value1' FOR UPDATE;
begin
   for c1 in s1 loop
      update tab1 set col1 = 'value2'
      where current of s1; i := 1 + 1;
      -- Commit after every X records
      if i > 1000 then commit;
         i := 0;
      end if;
   end loop;
   commit;
end;