用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/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/9240380/viewspace-748958/