I am running a very basic select against an oracle database (not sure of the version).
SELECT * FROM ACCOUNTING WHERE ID = 123456 ORDER BY DATE
I want to return only the most recent record. So I have tried ...
SELECT ROWNUM, * FROM ACCOUNTING WHERE ID = 123456 ORDER BY DATE
SELECT * FROM ACCOUNTING WHERE ID = 123456 AND ROWNUM < 2 ORDER BY DATE
I get the same result every time ...
Error Source: System.Data.OracleClient
Error Message: ORA-00904: "ROWNUM" : invalid identifier
Everything i see and read suggests that this should work. Can anyone see what I am missing? Could this be an issue with the driver? I am using the following package ... (Oracle ODAC 11.20.30 x64)
UPDATE
Thank you for all your replies ... I apologize for any confusion I created in my efforts to simplify the scenario. The ODAC driver is actually breaking the query out and formatting it for me, so what I originally posted is not exactly the query being run ... here's, specifically what the driver is spitting out that is generating the error ...
SELECT "ROWNUM", ID, SITE_ID, READING_DATE, SUBMITTED_DATE, DEPOSIT_DATE
FROM ACCOUNTING
WHERE (SITE_ID = 33730)
ORDER BY READING_DATE
And for my second attempt ...
SELECT ID, SITE_ID, READING_DATE, SUBMITTED_DATE, DEPOSIT_DATE
FROM ACCOUNTING
WHERE (SITE_ID = 33730) AND ("ROWNUM" < 2)
ORDER BY READING_DATE
Your actual query might be using
ROWNUM
within double quotes. Otherwise, this error is not possible.Though your first query would be
ORA-00936: missing expression
ROWNUM
is a pseudo-column and it is like function without parameters.. and by the way"ROWNUM"
makes oracle to search for such a column in your table..Quoted identifiers when is a Oracle reserved keyword, would surpass its original purpose, and behaves as user defined column.
Unsure, of how to stop the Query builder to interpret this way. I would consider this a BUG.