Skip to content
Advertisement

How to get old variable value from PL/SQL for loop?

I am trying to get old value from variable in PL/SQL for loop.

For instance:

I have l_sequnce variable with increment of 10.

I hope I described the problem well 🙂

Advertisement

Answer

Use ORDER BY in the SELECT statement and then you only need to check if the value has changed between the previous and current values:

Or, don’t use PL/SQL and do it all in an SQL statement using the DENSE_RANK analytic function:


If you want to do it entirely in PL/SQL and cannot use ORDER BY then use an associative array:

or:

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