Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6722883
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:30:05+00:00 2026-05-26T09:30:05+00:00

I have a procedure that goes like this: create or replace PROCEDURE NEWJOBIDPROC (JOB_ID

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T09:30:06+00:00Added an answer on May 26, 2026 at 9:30 am

    See the link @derobert provided for more information, but for your particular example you could do this:

    UPDATE JOB_TABLE SET VALUE = VALUE +1 WHERE ID = 50
     RETURNING VALUE INTO JOB_ID;
    

    But – have you not considered using a Sequence instead?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a stored procedure that goes something like this (pseudo code) storedprocedure param1,
I have a stored procedure call that goes like this: using (OracleConnection con =
I have a stored procedure that goes like this: ALTER PROCEDURE [dbo].[AuthenticateUser] @AzUserName varchar(20),
I have a stored procedure that looks like: CREATE PROCEDURE dbo.usp_TestFilter @AdditionalFilter BIT =
The scenario goes like this: I have a picture of a paper that I
I have this procedure that executes another procedure passed by a parameter and its
I have this stored procedure, that reads data from xml and make some inserts
I have a SQL Server 2008 stored procedure (pseudocode below) that goes as follows:
I have a function like this, that I would like to refactor function Myfunction(sUrl,
So if a language provides higher order procedure then I can have procedure that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.