I need some help with a query.
I want to select row count value from a table, and then to use the value in a different query. For example:
@rowcount = select count(*) from MyTable
select A*@rowcount, B/@rowcount
from MyOtherTable
Can someone show my what is the correct syntax? I need to use @rowcount
a lot of times so i prefer to calculate it only once.
In Oracle you can't mix procedural code and regular SQL like that.
But if you use this:
Oracle will evaluate the
count(*)
only once. There is no need to store the value somewhere to improve performance.If you want, you could move this into a common table expression: