Skip to content

Instantly share code, notes, and snippets.

@LazaroIbanez
Created October 31, 2017 19:38
Show Gist options
  • Save LazaroIbanez/e6a26cf14edbfd6ce0ed9acb5de2367e to your computer and use it in GitHub Desktop.
Save LazaroIbanez/e6a26cf14edbfd6ce0ed9acb5de2367e to your computer and use it in GitHub Desktop.
MassiveUpdate.sql Massive update using CURSOR FOR LOOP and UPDATE
SET SERVEROUTPUT ON
DECLARE
   inFindString      VARCHAR2(100);
   inReplaceString   VARCHAR2(100);
   countRecords      NUMBER;
   CURSOR c1 IS select variable_im_interested from table_to_update where col_to_update like '//old_string_to_find/%';
BEGIN
  Dbms_Output.Put_Line('Starting: ' || Systimestamp);
  inFindString := '//old_string_to_find/';
  inReplaceString := '//new_string/';
  FOR c1_rec IN c1 LOOP
    update table_to_update set col_to_update = replace(col_to_update, inFindString, inReplaceString) where variable_im_interested = c1_rec.variable_im_interested;
  END LOOP;
  COMMIT;
  select count(*) into countRecords from table_to_update where col_to_update like '//old_string_to_find/%';
  DBMS_OUTPUT.PUT_LINE('Total rows updated: ' || countRecords);
  DBMS_OUTPUT.PUT_LINE('Finished: ' || Systimestamp);
END;
/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment