--定义锁名
vLockname := 'lock_name';
--分配lock handle
DBMS_LOCK.ALLOCATE_UNIQUE(vLockname,vLockhandle);
--请求锁
vLockresult :=DBMS_LOCK.REQUEST (vLockhandle,timeout => 0,
lockmode => DBMS_LOCK.x_mode);
--判断脚本是否还在运行,是的话退出,并写日志到logtable,以备参考
IF vLockresult <> 0 THEN
insert into logtable values (vLockname ||' is already running, please check if you setup duplicated jobs!');return;
END IF;
--脚本运行完毕,解锁
vLockresult := DBMS_LOCK.RELEASE (vLockhandle);
vLockname: 定义的锁名
vLockhandle: 对应的handle
vLockresult: 请求锁返回的结果