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 401817
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T17:04:07+00:00 2026-05-12T17:04:07+00:00

Is there a way that one can test if a row has been locked

  • 0

Is there a way that one can test if a row has been locked for update in Oracle?

As an example, suppose the following query, performed by one user:

select * from SOME_TABLE where THE_ID = 1000 for update;

With another user I want to check if the row with THE_ID = 1000 is locked. If I try an update or something the second user gets blocked and remains waiting (do not want that).

I have also tried running the following query with the second user:

select * from SOME_TABLE where THE_ID = 1000 for update NOWAIT;

Since I can not place two locks on the same row this will fail. And it does. I get an “ORA-00054: resource busy and acquire with NOWAIT specified error”. Can I always count on this error to check the presence of the lock, or is there a simpler and cleaner way of determining if a row is locked?

Thank you!

  • 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-12T17:04:07+00:00Added an answer on May 12, 2026 at 5:04 pm

    You can write a procedure with the FOR UPDATE NOWAIT and return an error message when the row is locked:

    SQL> CREATE OR REPLACE PROCEDURE do_something(p_id NUMBER) IS
      2     row_locked EXCEPTION;
      3     PRAGMA EXCEPTION_INIT(row_locked, -54);
      4  BEGIN
      5     FOR cc IN (SELECT *
      6                  FROM some_table
      7                 WHERE ID = p_id FOR UPDATE NOWAIT) LOOP
      8        -- proceed with what you want to do;
      9        NULL;
     10     END LOOP;
     11  EXCEPTION
     12     WHEN row_locked THEN
     13        raise_application_error(-20001, 'this row is locked...');
     14  END do_something;
     15  /
    
    Procedure created
    

    Now let’s build a small example with two sessions:

    session_1> select id from some_table where id = 1 for update;
    
            ID
    ----------
             1
    
    session_2> exec do_something(1);
    
    begin do_something(1); end;
    
    ORA-20001: this row is locked...
    ORA-06512: at "VNZ.DO_SOMETHING", line 11
    ORA-06512: at line 2
    
    session_1> commit;
    
    Commit complete
    
    session_2> exec do_something(1);
    
    PL/SQL procedure successfully completed
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

just wondering is there any way that I can return one value from my
Is there a way to join tables on one field that represents a series
Is there a way to integrate iAd and AdMob in one project so that
is there any way of making sure that, one user is logged in only
Is there a way to obtain the stored value, that is, the one in
Is there way that I can read the file from remote server using fopen
Is there any way that I can wrap a checkboxlist in asp.net so that
Is there any way that I can make it so when someone clicks save
Is there any way that I can programmatically create (and I guess access) hidden
Is there any way that I can change how a Literal of a code

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.