Suppose you have a PL/SQL function that returns some random value that you will use in SQL sentence both as return data and in the Order by clause.
Now you can write an Order by clause in three different ways:
By index
Select Foo, MyFunction(Foo) orderField From FooTable Order By 2
Calling the function again
Select Foo, MyFunction(Foo) orderField From FooTable Order By MyFunction(Foo)
Using the order field alias
Select Foo, MyFunction(Foo) orderField From FooTable Order By orderField
The third way is possible, since the Order by clause is the last of what needs to be analyzed, and then Oracle already knows about this alias.
My question is, is there a difference in processing or executing these three queries? In particular, will there be a second call that the MyFunction call will be evaluated again?
I tried to find out by looking at the documents, and also ran some queries from Toad, and also looked at explain plan , but still could not find a significant difference.
My version of Oracle is 11.2.0.3.0, if that matters.
source share