OracleCommand command, ExecuteNonQuery issue

前端 未结 4 1090
难免孤独
难免孤独 2021-01-20 03:28

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         


        
相关标签:
4条回答
  • 2021-01-20 03:44

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

    0 讨论(0)
  • 2021-01-20 03:59

    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.

    0 讨论(0)
  • 2021-01-20 04:02

    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.

    0 讨论(0)
  • 2021-01-20 04:05

    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.

    0 讨论(0)
提交回复
热议问题