OracleCommand command, ExecuteNonQuery issue

℡╲_俬逩灬. 提交于 2019-12-01 19:00:48

Have you forgotten to commit your changes in Toad (or any other client)? An open transaction will cause it to wait indefinitely.

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!