Skip to content
Advertisement

Oracle Case Statement and efficency

I have a piece of my Oracle Query i need to optimize a little

line.quantity comes out from other part o query, for this example is not needed i think. I would like to calculate only once SUM(dnl.quantity) instead ad every iteraciotn, somethink like

But obviously this give error at the second and 3rd WHEN

Advertisement

Answer

You are over-optimizing. The Oracle compiler can decide how many times it wants to evaluate sum(dnl.quantity). However, the data movement is usually much more expensive than the calculation of aggregations on a single column.

That said if you are really concerned about this, you can use sign():

Or to be more inscrutible:

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement