I want to increase a value N in my database but the problem : my application is used by several users on the same moment. So, only one user must increase the value N at the time T to avoid to have 2 inserts with the same value N. So i want to use the principe of mutual exclusion on a field of my database..
How can I do this?
thank you in advance for your response!
You could select with a lock on the table, before increasing the value "N". The only issue is that the user that first does this operation should select it and update it quite fast so that others do not wait on the lock to be realeased.
More elaboration from another Oracle person....
If the subset of rows that need to be updated is known, he could use a SELECT...FOR UPDATE WHERE <conditions> followed by an UPDATE statement. The
SELECT FOR UPDATE places locks on the rows in question. The row locks will be released, when the UPDATE is COMMITted. The window
between the SELECT FOR UPDATE and the commit will determine the concurrency.