Sorry, this is a nerds-only post, the rest of you will not find this amusing or interesting. BTW, this problem is NOT well documented on the web.
Last week, I was working on a Delphi program. I needed to get the next version number of something from the Oracle database. So I wrote a SQL statement that went something like this:
select max(version) from table where ...
This worked great, and gave me the exact result I was looking for, until I added it into my TADOQuery and tried to use it. It gave me a "ORA-00937: not a single-group group function" error.
The only problem is that the SQL I sent in is a single-group group function.
After getting the database guy involved, and doing a major rectal exam on my program while it was running, we found that the SQL I had crafted was being transmogrified before it reached the database for execution. It looked vaguely like this (emphasis added):
select max(version), RowID from table where ...
RowID?!? Where the heck did that come from? As it turns out, there is a property in Delphi's TADOQuery object called locktype. By default, this property is set to ltOptimistic. This mode assumes that I want to read data out of the database, edit it, and send the updates back in. In order to do that, it needs to know exactly which row to update, so of course it had to add RowID to the query.
The only bad thing about that is that a component assumed it would know better than me what my program was doing, and modified my code in secret to help me out. This help led to a debugging nightmare that took me all day to diagnose and crush. The actual fix is to set the locktype property to ltReadOnly. This mode doesn't need the RowID, so it leaves your SQL alone.
Great design, guys.


10 comments:
I have exactly the same problem. Couldn't seat for a whole day - until I stumbled into your blog entry - thank you!
I had the same issue - it was messing with my head until I found this article.
Thanks a lot.
Dude, same thing happened to me. But I ran the sql in sql*plus.. still cant figure out the prob...
I'm seeing the same problem with max() in sql*plus too. Grr.
You helped me very much.
This was a problem a colleague of mine was tracking for hours and days. After I fortunately found your blog, the problem was solved after a few minutes!
This error can start happening if CURSOR_SHARING is not set to EXACT on the Oracle server.
Wonderful job done!!!!
Thanks to GOOGLE also to point me here.
I found the problem quickly, but without this solution I would still be busy. Thank you.
Thank you for this Blog. This helped me fix a problem in less then 4 minutes.
Thanks for this post!
Had this exact issue and solved it by setting CURSOR_SHARING to exact.
Excellent.
Post a Comment