I need to do an update to reorder records in a table in an Oracle 9 bank. This table stores records that are requests made by users to TI. So, briefly, I have the following fields in the table:
PK | NOME DEMANDA | PRIORIDADE
------------------------------
1 | DEMANDA 1 | 1
2 | DEMANDA 2 | 2
3 | DEMANDA 3 | 3
4 | DEMANDA 4 | 4
5 | DEMANDA 5 | 5
The priority is who determines which project will be done first by IT. For business reasons, it may be necessary to change the priority of the demands. At this point we come to the problem. How to reorder demands for priority? For example, I could have Demand 4 as a priority, and the table would look like this:
PK | NOME DEMANDA | PRIORIDADE
------------------------------
1 | DEMANDA 4 | 1
2 | DEMANDA 1 | 2
3 | DEMANDA 2 | 3
4 | DEMANDA 3 | 4
5 | DEMANDA 5 | 5
Any tips?
UPDATE 1 - Improved problem definition
The problem is at the moment of the update. The user can, within the system, set the priority of the demand. Imagine that he is editing demand number 4 that has priority 4. He can change the priority to 1. So, basically the update would be something like: update table set priority = 1 where priority = 4. But update is not enough, you have to reorder all other demands.
If I simply do the update I am saying that the demand that had priority 1 now has priority 4. The correct would be that the demand with priority 1 changes to 2. The demand with priority 2, change to 3 and etc. ... until you reach demand 4.
The end result would be:
PK | NOME DEMANDA | PRIORIDADE
------------------------------
1 | DEMANDA 4 | 1
2 | DEMANDA 1 | 2
3 | DEMANDA 2 | 3
4 | DEMANDA 3 | 4
5 | DEMANDA 5 | 5