I have to clear certain tables in the oracle database however when I\'m having issues with running the following code
public static void ClearDataTables(ILis
Have you forgotten to commit your changes in Toad (or any other client)? An open transaction will cause it to wait indefinitely.
I would probably write a stored procedure that does all of the deletions or truncations and invoke the SP once, rather than have a loop client-side.
EDIT: It would also be better not to create the command object inside the loop. Create it once outside the loop with a table-name parameter, and then invoke it feeding it a different parameter value with each iteration. But the SP is to be preferred.
Is there a lot of data in that table? This would explain, why it takes so long to delete the data.
Anyway, I suggest to use TRUNC
for clearing tables.
Large number of deletes can be very slow, especially if you run them in one transaction. If you don't need the transaction at all, use:
truncate table YourTable
If you do, split the delete
over small-sized transactions. Basically run:
delete from YourTable where rownum < 100
until the table is empty. See for example this blog post.