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.

1
Leave a Reply

avatar
1 Comment threads
0 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
1 Comment authors
Mahendra Kothari Recent comment authors
  Subscribe  
newest oldest most voted
Notify of
Mahendra Kothari
Guest
Mahendra Kothari

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.