Hi Niall, I'm taking transactions from a staging table and loading them into another table. I'm using the sequence to generate surrogate key values for the Target table. The problem is I need to batch the transactions into buckets based on certain criteria and the sum of the amounts in a bucket can't exceed a certain value. I resorted to a plsql loop to do this. The logic requires that the records in the cursor are sorted and that's where I ran into the issue with sorting and sequences. I could leave the sequence out of the query and increment the sequence for each iteration of the loop but I wasn't mad about that idea as I think (could be wrong) that that would involve a context switch each time the sequence was incremented. That make any sense? Thanks, Fergal On 31 Jan 2013 19:11, "Niall Litchfield" <niall.litchfield@xxxxxxxxx> wrote: > I'm confused as to the purpose of a sequence.nextval in the select. The > query will return different results each time it is run surely. You could > probably store a hi gh value in a 1 row table and use the connect by prior > trick, but it seems like we're missing important details. > -- //www.freelists.org/webpage/oracle-l