create table lock_test ( action varchar(10), when date );
declare v_lockhandle varchar2(200); v_result number; begin dbms_lock.allocate_unique('control_lock', v_lockhandle); v_result := dbms_lock.request(v_lockhandle, dbms_lock.x_mode); if v_result <> 0 then dbms_output.put_line( case when v_result=1 then 'Timeout' when v_result=2 then 'Deadlock' when v_result=3 then 'Parameter Error' when v_result=4 then 'Already owned' when v_result=5 then 'Illegal Lock Handle' end); end if; end; /
declare v_result number; v_lockhandle varchar2(200); begin dbms_lock.allocate_unique('control_lock', v_lockhandle); v_result := dbms_lock.request(v_lockhandle, dbms_lock.ss_mode); if v_result <> 0 then dbms_output.put_line( case when v_result=1 then 'Timeout' when v_result=2 then 'Deadlock' when v_result=3 then 'Parameter Error' when v_result=4 then 'Already owned' when v_result=5 then 'Illegal Lock Handle' end); end if; insert into lock_test values ('started', sysdate); dbms_lock.sleep(5); insert into lock_test values ('ended' , sysdate); commit; end; /
declare v_lockhandle varchar2(200); v_result number; begin dbms_lock.allocate_unique('control_lock', v_lockhandle); v_result := dbms_lock.release(v_lockhandle); if v_result <> 0 then dbms_output.put_line( case when v_result=1 then 'Timeout' when v_result=2 then 'Deadlock' when v_result=3 then 'Parameter Error' when v_result=4 then 'Already owned' when v_result=5 then 'Illegal Lock Handle' end); end if; end; /
TO_CHAR(WHEN,'DD.MM ACTION ------------------- ---------- 30.10.2005 12:16:13 started 30.10.2005 12:16:13 started 30.10.2005 12:16:18 ended 30.10.2005 12:16:18 ended
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/25164132/viewspace-749178/ ,如需转载,请注明出处,否则将追究法律责任。