답변:
DBMS_LOCK
독점 잠금 으로이 작업을 수행 할 수 있습니다 .
다음 절차를 참조하십시오.
CREATE OR REPLACE PROCEDURE myproc
IS
lockhandle VARCHAR2(128);
retcode NUMBER;
BEGIN
DBMS_LOCK.ALLOCATE_UNIQUE('myproclock',lockhandle);
retcode:=DBMS_LOCK.REQUEST(lockhandle,timeout=>0, lockmode=>DBMS_LOCK.x_mode);
IF retcode<>0
THEN
raise_application_error(-20000,'myproc is already running');
END IF;
/* sleep so that we can test with a 2nd execution */
DBMS_LOCK.sleep(1000);
retcode:=DBMS_LOCK.RELEASE(lockhandle);
END myproc;
/
테스트 (세션 1) :
SQL> BEGIN
2 myproc();
3 END;
4 /
(반환하면 분명히 반환 DBMS_LOCK.sleep()
).
테스트 (세션 2) :
SQL> BEGIN
2 myproc();
3 END;
4 /
BEGIN
*
ERROR at line 1:
ORA-20000: myproc is already running
ORA-06512: at "PHIL.MYPROC", line 12
ORA-06512: at line 2
SQL>
분명히 당신은해야합니다 GRANT EXECUTE ON DBMS_LOCK TO YOURUSER;
.