I have a procedure that goes like this:
create or replace
PROCEDURE NEWJOBIDPROC (JOB_ID OUT NUMBER )
--++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
-- PROCEDURE TO RETRIEVE THE JOB ID
--++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
IS
BEGIN
-- select the job_id
SELECT VALUE+1 INTO JOB_ID FROM JOB_TABLE WHERE ID = 50;
-- update table JOB_TABLE with the latest job id
UPDATE JOB_TABLE SET VALUE = JOB_ID WHERE ID = 50;
END;
Now my question is the following.
Let us say I have multiple calls to this procedure at the same time.
In our example let us make that two simultaneous calls to the same procedure.
When both of them run the select statement they receive some value – let it be 200.
Now, they will both make an update to the job_table, with the same value of 200 – which is not what I want. I don’t want duplicates.
So, how do I mark the whole code as atomic? I want the select and the update to run at the same time and be thread safe. I want two statements together to be marked as atomic.
See the link @derobert provided for more information, but for your particular example you could do this:
But – have you not considered using a Sequence instead?