1
I need to update to reorder records in a table in an Oracle 9 database. This table stores records that are requests made by users to IT. So, briefly, I have in the table the following fields:
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 demands. At this point we come to the problem. How to reorder demands for priority? For example, I could have demand 4 as a higher 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 hint?
UPDATE 1 - Better definition of the problem
The problem is at the time of updating. The user can, within the system, set the demand priority. Imagine that he is editing demand number 4 which 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 not just the update, you need 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 one would be that the demand with priority 1 change to the 2. The demand with priority 2, change to the 3 and etc... until arriving in 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
I didn’t understand the problem. It wouldn’t just be your query having a
order by prioridade
??– rLinhares
Do you want to sort the display by priority, or do you want to change the priorities with some other reference ? Post an example of what the ending would look like...
– rbz
Oops. I changed the question to make it clearer.
– Washington Morais
the priority must be unique then
– Rovann Linhalis
supondo
tabela (PK,DEMANDA,PRIORIDADE)
criar uma procedure do tipo altera_demanda (pdemanda,ppriode,pprioate) , 
faz um update da demanda para pprioate e depois um cursor alterando toda
as demenadas diferentes de pdemanda e maiores que pprioate somando 1
to the priority , I’m a little tied up here to write the SP but will the basic idea the apps would call this sp
– Motta