Oracle pl/sql: executing dynamic delete within a transaction

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


Oracle pl/sql: executing dynamic delete within a transaction



I need to delete one or more row from list of tables stored in a table, and commit only if all deletion succeed.
So I wrote something like this (as part of a bigger procedure):


BEGIN
SAVEPOINT sp;

FOR cur_table IN (SELECT * FROM TABLE_OF_TABLES)
LOOP
EXECUTE IMMEDIATE 'DELETE FROM ' || cur_table.TABNAME || ' WHERE ID = :id_bind'
USING id;
END LOOP;
EXCEPTION
WHEN OTHERS THEN
ROLLBACK TO SAVEPOINT sp;
END;



I know this couldn't work, because of the "execute immediate".



So, what is the correct way to do that?





what is the issue? are you having an error, a wrong result, ... ?
– Aleksej
1 hour ago





I haven't tried yet. I guess "execute immediate" commit itself. Is that wrong?
– MonkeyH
1 hour ago





it does not commit
– Aleksej
1 hour ago





id doesn't seem to be defined anywhere. Also, an anonymous block like this will roll back on failure anyway, so you don't need the savepoint and exception handler.
– William Robertson
31 mins ago




id





Yes, my fault. It's part of a bigger procedure.
– MonkeyH
3 mins ago









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Arduino Mega cannot recieve any sketches, stk500_recv() programmer is not responding

Visual Studio Code: How to configure includePath for better IntelliSense results

C++ virtual function: Base class function is called instead of derived