Learning While Aging

ORA-01745: invalid host/bind variable name, caused by reserved word in query

I wrote a simple parameterized query the other day against an Oracle database as follows:

SELECT DISTINCT E.ID, E.Name, E.Department FROM Employee E WHERE E.ID = :uid

Then in my application, I assign the value to the parameter as follows:

cmd.Parameters.Add(new OracleParameter(":uid", OracleDbType.Varchar2));

However, when I was trying to run my application, I got an error saying:

ORA-01745: invalid host/bind variable name

Can you see what is causing the error?

It took me hours of Google search until I realized that “uid” is actually a keyword in Oracle, even though there is a “:” colon in front of it, Oracle still thinks it is a reserved word and throw the error above. I am going to faint.

0 0 votes
Article Rating
1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Mahendra Kothari
Mahendra Kothari
9 years ago

This was excellent catch. I had the same problem until I search web and used your answer to add 1 to each of my bind variables and the error disappeared. Now I have to find which one is the oracle keyword.

Thanks a lot.