Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

When is GROUP BY evaluated - SQL query help

xxsawerMar 17 2014 — edited Mar 19 2014

Hi everybody,

I am being desperate from one of my queries, any help is really appreciated.

The problem is following:

Consider a table called 'NAMES' with a name and gender columns. It will be filled with three male names, so gender column would be always 'male'. Now I have following query:

SELECT *

  FROM (SELECT COUNT(*), GENDER

          FROM NAMES

         GROUP BY GENDER)

WHERE SomeFunction(GENDER) = 1;

Now if I put logging into function "SomeFunction", I see it is called three times. Why?

The inner select should return only one row, so I would suppose that the function should be called only once.

How should I rewrite the select statement to call "SomeFunction" only once as expected?

Thanks for help, Dan

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 16 2014
Added on Mar 17 2014
17 comments
952 views