ORA-01745: invalid host/bind variable name ERROR in Delphi when we use Oracle DB

I received the above error message when TADOQuery.Open method is called. I checked the SQL of TAdoquery component which looked fine to me but was still getting errors. SQL was as follow

AdoQuery1.Sql.text := 'SELECT * FROM EMPLOYEE E WHERE E.JOINDATE < :DATE';
AdoQuery.Open; //---ABOVE ERROR RAISED----//

After researching the issue, I found that the issue is with :DATE parameter that I have used in SQL. Apparently the word "DATE" is a reserved word in Oracle, and therefore cannot be used as a SQL parameter or bind variable name. You can not use a key word as parameter name. 

So I replaced the :DATE parameter with :JDATE in SQL as follow and it worked fine without any error.

AdoQuery1.Sql.text := 'SELECT * FROM EMPLOYEE E WHERE E.JOINDATE < :JDATE';
AdoQuery.Open; //---ERROR RESOLVED----//

So please note* that you should not use any reserve keywords as  parameter while writing SQL in Delphi side.

Some of the common Oracle reserve keywords we use as parameter in SQL in Delphi side which we should avoid.
Example
:Start, :Date, :end, :number, :user, :rowid, :Rownum, :desc

For detail list of Oracle reserved words please visit following link...


Comments

Popular posts from this blog

ShellExecute in Delphi

How to send Email in Delphi?

Variants in Delphi. Use of Variant Array. How to check a Variant is unassigned or empty or clear ?