Skip to Main Content

Developer Community

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Sequentially update a column with a decrementing value

user4434979Nov 24 2023 — edited Nov 24 2023

In the PLSQL table in the screen cap below I need a script to update the "QTY_REQ" column sequentially row by row by dividing out a number (e.g. 7) among the rows. I want to start with the row with the highest value in QTY (QTY 4, LOC 10800B41) and enter 4 for QTY_REQ. Then go to the second row (QTY 2, LOC 10800A01) and enter 2 for QTY_REQ. Then finally go to the third row (QTY 2, LOC 10800B01) and enter 1 for QTY_REQ. So I evenly divide out the values and stop when the total is reached. The number could be 5 and would just fill in the first two rows (4 entered for for QTY_REQ for the first and 1 entered for for QTY_REQ for the second).

Important point; the value that is entered for QTY_REQ cannot be higher than the value that is in the QTY column for that row. but it must be the maximum of that column if possible. The only situation in which that might not be possible is when the last row is being updated and the number left to enter is 1.

The script that creates the table is here: https://file.io/fryZeKgxFMZG

If someone can help with this that would be appreciated, thank you

Comments
Post Details
Added on Nov 24 2023
1 comment
166 views