Break the LOCK which came from another session

Hello everyone,

Please help me solve this problem.

My problem is to break the lock shot Session S1, S2 Session.

I'm using the dbms_lock package functions.

Session " S1 " run these 2 statements:

DBMS_LOCK.allocate_unique (mon_contexte, handle);

status: = dbms_lock.request (handle, dbms_lock. (X_MODE, li_timeout);

"S1" can release his own lock:

DBMS_LOCK.allocate_unique (mon_contexte, handle);

status: = dbms_lock.release (handle);

But ' S2 ' cannot override " S1 " shot lock using the same function "dbms_lock.release". ==> OK!

My question is: session 'S2' how can I break the lock obtained by 'S1' no kill 'S1 '? (something like killing only the locking process)

Thanks in advance...

I'm not sure that understand the problem you are experiencing.

If I have a single receiver program that waits for 1 second and processes for 10 (treatment here is simulated by call dbms_lock.sleep), the receiver will be get signal when it then calls waitone.

declare
  l_msg varchar2(1000);
  l_status integer;
begin
  dbms_alert.register( 'foo_alert' );
  loop
    dbms_output.put_line( 'Started waiting at ' || to_char( sysdate, 'hh24:mi:ss' ) );
    dbms_alert.waitone( 'foo_alert', l_msg, l_status, 1 );
    if( l_status = 0 )
    then
      dbms_output.put_line( 'Alert received: ' || l_msg );
      exit;
    end if;
    dbms_output.put_line( 'Started sleeping at ' || to_char( sysdate, 'hh24:mi:ss' ) );
    dbms_lock.sleep( 10 );
  end loop;
end;

If the session 1 runs this code and session 2 reports alert while 1 is in the call of dbms_lock.sleep

SQL> exec dbms_alert.signal( 'foo_alert', 'My message sent at ' || to_char( sysdate, 'hh24:mi:ss') );
PL/SQL procedure successfully completed.

SQL> commit;
Commit complete.

Session 2 will be notified of the signal when he returns the call to WAITONE.  Note that the message has been sent 3 seconds after the first call to WAITONE had expired (and thus 3 seconds in the 'work' simulated by DBMS_LOCK. (SLEEP).  The signal has been received once this piece of work was completed, and the loop went back to waiting on the alert.

SQL> ed
Wrote file afiedt.buf

  1  declare
  2    l_msg varchar2(1000);
  3    l_status integer;
  4  begin
  5    dbms_alert.register( 'foo_alert' );
  6    loop
  7      dbms_output.put_line( 'Started waiting at ' || to_char( sysdate, 'hh24:mi:ss' ) );
  8      dbms_alert.waitone( 'foo_alert', l_msg, l_status, 1 );
  9      if( l_status = 0 )
 10      then
 11        dbms_output.put_line( 'Alert received: ' || l_msg );
 12        exit;
 13      end if;
 14      dbms_output.put_line( 'Started sleeping at ' || to_char( sysdate, 'hh24:mi:ss' ) );
 15      dbms_lock.sleep( 10 );
 16    end loop;
 17* end;
SQL> /
Started waiting at 18:07:45
Started sleeping at 18:07:46
Started waiting at 18:07:56
Alert received: My message sent at 18:07:49

PL/SQL procedure successfully completed.

Justin

Tags: Database

Similar Questions

Maybe you are looking for