I am trying to delete records from an Oracle table before inserting new ones using a sql command and a parameter because the value comes from the browser.
This is the code:
var tableName = "<myTableName>";
context.Database.ExecuteSqlCommand("DELETE :p0", tableName);
Oracle is throwing "ORA-00903: invalid table name".
I have also tried:
context.Database.ExecuteSqlCommand("DELETE :p0", new OracleParameter("p0", OracleDbType.VarChar, 200, tableName, ParameterDirection.Input)
Is there something simple I am missing?
If you bounce the table against
ALL_TABLES
you should be able to prevent any SQL Injection attacks:On DevArt, I think the
Add
would instead beAddWithValues
but would otherwise look the same.In this case, a return value of false meant there was no such table. This all presupposes the user has the ability to delete from the table in question.
Also, if possible, a
truncate
is a nice alternative to adelete from
. It's quite a bit faster and resets the high water mark. I think you need to be an owner or have the "drop any table" privilege to do this, but there are other ways around it -- for example, have the DBA set up a stored procedure to do the truncation on certain tables.