I need to clear certain tables in oracle database, however, when I have problems running the following code
public static void ClearDataTables(IList<string> tableNames) { string connectionString = "CONNECTIONSTRING"; using (OracleConnection connection = new OracleConnection()) { connection.ConnectionString = connectionString; connection.Open(); foreach (string table in tableNames) { OracleCommand command = connection.CreateCommand(); string sql = String.Format("DELETE FROM TOA_REPORTING.{0}", table); command.CommandText = sql; command.ExecuteNonQuery(); } connection.Close(); } }
I call this method with this list
ClearDataTables(new List<string> { "GROUP_DEFINITION", "GROUP_REPORT_EMAIL_LIST", "GROUP_EQUIPMENT_GROUP_STN_XREF"});
It starts the first two tables perfectly, however on the third it gets stuck, and the application starts forever ...
It's funny when I switch "GROUP_REPORT_EMAIL_LIST" and "GROUP_EQUIPMENT_GROUP_STN_XREF", the application starts forever after it gets into the middle name of the table.
So in conclusion, the function runs forever when it falls into "GROUP_EQUIPMENT_GROUP_STN_XREF". I checked that the generated SQL works by checking it on the toad.
Has anyone else encountered this problem?
EDIT - The first two tables are really cleared when they are started.
Decision
string connectionString = "CONNECTIONSTRING"; using (OracleConnection connection = new OracleConnection(connectionString)) { connection.Open(); OracleCommand command = connection.CreateCommand(); OracleTransaction trans = connection.BeginTransaction(); command.Transaction = trans; foreach (string table in tableNames) { string sql = String.Format("DELETE FROM TOA_REPORTING.{0}", table); command.CommandText = sql; command.ExecuteNonQuery(); } trans.Commit(); }
TRUNCATE would be a very pleasant solution, however I do not have privileges for this!