1

Topic: Reading not all sampling

Situation:
There is conditionally such label:
count
1
3
3
2
5
...
Also there is a certain parameter, whether which needs to be checked up the total count exceeds parameter or not
Most simple it is natural to make in a forehead

select sum (count) into sum_count from table;
if sum_count> = param_sum_count then
Exceeded

But records much also it would be desirable to optimize, I need to read records until then while sum (count) <param_sum_count and as soon as sum (count)> = param_sum_count to stop to read.
There is still an idea through bulk collect limit 1, but it would be desirable SQL to manage if it probably.

2

Re: Reading not all sampling

Cheese)));
If there is an index - it is possible to be perverted with rec with, but it is better packs  from the cursor.

3

Re: Reading not all sampling

There is an index across the field to which search, but not on which I calculate.
It is possible an example with rec with?

4

Re: Reading not all sampling

Cheese)));
Wrote here.
Part 2.
Chapter 1. When PL/SQL is better than Vanilla SQL.
Section Specifics of analytical functions
Subsection sampling Interruption.
P. 117