Create a "barrier" (prevent parallel execution) in Oracle PL/SQL?
Oracle has several locking mechanisms that you can use to serialize operations:


You could create a single-row table that is locked at the beginning of the procedure. The lock will be locked until the transaction ends (commit/rollback).
You could request a lock with DBMS_LOCK.request. This lock can be maintained for the duration of the session or until you call DBMS_LOCK.release. This lock can be maintained across commits.


Example of serialization using DBMS_LOCK:

SQL&gt; CREATE OR REPLACE PROCEDURE serial IS
  2     l_lock_handle  VARCHAR2(128 BYTE);
  3     l_lock_request INTEGER;
  4  BEGIN
  5     dbms_lock.allocate_unique(lockname=&gt; 'MY_SERIAL_PROC', lockhandle =&gt; l_lock_handle);
  6     LOOP
  7        l_lock_request := dbms_lock.request(lockhandle        =&gt; l_lock_handle,
  8                                            timeout           =&gt; 5,
  9                                            release_on_commit =&gt; FALSE);
 10        CASE l_lock_request
 11           WHEN 0 THEN
 12              EXIT; -- success
 13           WHEN 1 THEN
 14              dbms_output.put_line('lock already reserved, wait...');
 15              dbms_lock.sleep(5); -- sleep 5 seconds before retrying
 16           ELSE
 17              raise_application_error(-20001, 'Lock error: ' || l_lock_request);
 18        END CASE; --
 19     END LOOP;
 20     ----------------------------------------
 21     -- serialized block of code           --
 22     -- (lock will be kept accross commit) --
 23     ----------------------------------------
 24     dbms_lock.sleep(30);
 25     ----------------------------------------
 26     -- End of serialized code             --
 27     ----------------------------------------
 28     l_lock_request := dbms_lock.release(lockhandle =&gt; l_lock_handle);
 29  END;
 30  /

Procedure created


Only one session can run this procedure at the same time:

session1&gt; exec serial;             
                                   session2&gt; exec serial;
                                   lock already reserved, wait...
                                   lock already reserved, wait...
                                   lock already reserved, wait...

PL/SQL procedure successfully completed                            

                                   PL/SQL procedure successfully completed.