Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Create a lock and loop til lock is released in procedure

oraLaroSep 3 2020 — edited Sep 3 2020

Oracle 12.2

I have a procedure that may be called by multiple sessions at once but I only want 1 to be working at a time, how can I build a lock into a procedure call so that a session will wait until the lock is free before proceeding.

Something like

create or replace procedure my_proc

as

begin

while tab_lock is true

     loop

       check tab_lock if true then loop;

            else

         exit;

     end loop;

tab_lock = true;

do something;

tab_lock = false;

end;

I dont mind if several proc calls are in that loop, I just need it so only 1 is working at a time.  Anyone know?

This post has been answered by Solomon Yakobson on Sep 3 2020
Jump to Answer
Comments
Post Details
Added on Sep 3 2020
5 comments
1,585 views