Created
October 31, 2017 19:38
-
-
Save LazaroIbanez/e6a26cf14edbfd6ce0ed9acb5de2367e to your computer and use it in GitHub Desktop.
MassiveUpdate.sql Massive update using CURSOR FOR LOOP and UPDATE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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