通過v$access檢視正在執行的儲存過程procedure

wisdomone1發表於2012-11-11

用v$access檢視,只要執行,就會在該檢視中有一條記錄!手工執行了一個commit,v$access裡的紀錄就消失

create or replace procedure plsqlconcurrencysample 

as

/* ** copyright*/

/* written by chao_ping to provide some sample for plsql concurrency control*/

v_lockhandle varchar2(4000);

v_result        number;

begin

dbms_lock.allocate_unique('PLSQL1',v_lockhandle); 

v_result:=dbms_lock.REQUEST(LOCKHANDLE=>v_lockhandle,timeout=>0);

if 

        v_result=0 then

        dbms_output.put_line('now begin to process ...at'||to_char(sysdate,'YYYYMMDD hh24:mi:ss'));

        dbms_lock.sleep(60);

        dbms_output.put_line('finished work at'||to_char(sysdate,'YYYYMMDD HH24:mi:ss'));

        v_result:=dbms_lock.release(lockhandle=>v_lockhandle);

else

        dbms_output.put_line('someone else working...');

end if;

exception

        when others then 

        dbms_output.put_line('ERROR'||sqlerrm);

        v_result:=dbms_lock.release(lockhandle=>v_lockhandle);

end;


--可以通過v$access查詢上述儲存過程是否正在執行

select * from v$access where type='PROCEDURE';


--上述可以查詢出sid,進而可以查詢出哪臺機器執行此儲存過程,再進行具體的處理

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/9240380/viewspace-748958/,如需轉載,請註明出處,否則將追究法律責任。

相關文章