Last active
September 15, 2018 22:12
-
-
Save realeroberto/abe2b5755dc366a46945 to your computer and use it in GitHub Desktop.
PL/SQL trick: delete rows in tranches.
This file contains hidden or 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
-- | |
-- delete rows in tranches | |
-- | |
-- inspired by the discussion at http://kr.forums.oracle.com/forums/thread.jspa?threadID=365130 | |
-- | |
set serveroutput on | |
DECLARE | |
ln_DelSize NUMBER := 500; | |
ln_DelCount NUMBER; | |
ln_Total NUMBER := 0; | |
BEGIN | |
LOOP | |
DELETE FROM table WHERE rownum <= ln_DelSize; | |
ln_DelCount := SQL%ROWCOUNT; | |
ln_Total := ln_Total + ln_DelCount; | |
EXIT WHEN ln_DelCount = 0; | |
COMMIT; | |
END LOOP; | |
dbms_output.put_line('deleted '||ln_Total||' rows'); | |
END; | |
/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment