Monday, June 4, 2012

ORA-00911: invalid character\n in Asp.Net


I got the error ORA-00911: invalid character\n while trying to execute the following Oracle query from Asp.Net

string strQuery = "SELECT * FROM PROJECTS;";

Tried to figure out what the \n meant, but surprisingly the reason for the error had nothing to do with the \n

Cause:
The additional ";" at the end of the SELECT query

Resolution:
Remove the ";" and the query will start working
string strQuery = "SELECT * FROM PROJECTS";
 
Additional Information:
The query will still work even with the ";" in Oracle editors like Oracle SQL Developer, but will throw the exception ORA-00911: invalid character\n in .Net, this made it even difficult to debug the issue, since the same query works fine in Oracle, but throws an exception when called from .Net, finally removed the ";" and resolved the issue.

The ";" is required only while running the query inside a code block like BEGIN.... END;

string strQuery = "BEGIN UPDATE PROJECTS SET Name = 'Dashboard Project' WHERE PROJECT_ID = 100; END;";

The above query works fine without any issues sicne it is placed in a code block, but a single SQL statement will throw the exception ORA-00911: invalid character\n, when a ";" is placed at the end.




Search Flipkart Products:
Flipkart.com

No comments: