I’m getting an oracle 00911 error (illegal character). I’m hoping someone can help me understand.
I’m using the following code to execute an sql statement on my oracle 11g database:
private DataTable ExecuteQuery(DbCommand query) {
DataTable result = new DataTable();
using (DbConnection con = CreateConnection()) {
try {
query.Connection = con;
query.CommandTimeout = int.MaxValue; // don't impose a timeout
using (DbDataAdapter dataAdapter = factory.CreateDataAdapter()) {
dataAdapter.SelectCommand = query;
dataAdapter.Fill(result);
}
}
...
If I give this function something with a DbCommand.CommandText property like "Select * from X;" it works fine, but given "Select * from x where y;" this will throw an oracle 00911 exception. If I remove the semicolon, however, it executes fine.
Does anyone know why it would throw an illegal character error for ending the statement with a semicolon only on certain types of statements?
Update for clarity:
The exact queries I used to test out the semi colon causing error were:
This query worked fine:
SELECT * FROM Machines;
This query generated an ORA 0911 error:
SELECT * FROM Machines WHERE ID = 47;
While this query worked fine:
SELECT * FROM Machines WHERE ID = 47 <– only the semi colon changed
Also the provider being used is Oracle.DataAccess.Client
This behaviour depends on the DB provider used – some providers do additional queries upfront (like a
SELECT COUNT(*)...) and/or add something to the query (likeROWIDfor example)… depending on how the provider implements this “internal behaviour” it might result in some strange things when a semicolon is present… it might even behave differently depending on whether aWHEREis present or not…In scenarios like yours (a pure
SELECT/UPDATE/DELETEstatement) I NEVER add a semicolon at the end and had never this problem…Out of curiosity: why do you have a semicolon at the end ?