C.7 DBMS_LOCKThe DBMS_LOCK package provides you with access to the Oracle Lock Management (OLM) services. With OLM, you can request a lock of a particular type, assign it a name that can then be used as a handle to this lock, modify the lock, and even release the lock. A lock you create with the DBMS_LOCK package has all the functionality of a lock generated by the Oracle RDBMS, including deadlock detection and view access through SQL*DBA and the relevant virtual tables. C.7.1 The ALLOCATE_UNIQUE procedureThe ALLOCATE_UNIQUE procedure allocates a unique lock handle for the specified lock name. The specification is: PROCEDURE DBMS_LOCK.ALLOCATE_UNIQUE (lockname IN VARCHAR2, lockhandle OUT VARCHAR2, expiration_secs IN INTEGER DEFAULT 864000); C.7.2 The CONVERT functionThe CONVERT function converts a lock from one type or mode to another. The specifications are: FUNCTION DBMS_LOCK.CONVERT (id IN INTEGER, lockmode IN INTEGER, timeout IN NUMBER DEFAULT MAXWAIT) RETURN INTEGER; FUNCTION DBMS_LOCK.CONVERT (lockhandle IN VARCHAR2, lockmode IN INTEGER, timeout IN NUMBER DEFAULT MAXWAIT) RETURN INTEGER; The function returns the status of the attempt to change the mode, as shown below:
C.7.3 The RELEASE functionThe RELEASE function releases the specified lock. This specifications are: FUNCTION DBMS_LOCK.RELEASE (id IN INTEGER) RETURN INTEGER; FUNCTION DBMS_LOCK.RELEASE (lockhandle IN VARCHAR2) RETURN INTEGER; In both cases, the RELEASE function returns a status with one of four values:
C.7.4 The REQUEST functionThe REQUEST function requests a lock of the specified mode. The specifications are: FUNCTION DBMS_LOCK.REQUEST (id IN INTEGER, lockmode IN INTEGER DEFAULT X_MODE, timeout IN NUMBER DEFAULT MAXWAIT, release_on_commit IN BOOLEAN DEFAULT FALSE) RETURN INTEGER; FUNCTION DBMS_LOCK.REQUEST (lockhandle IN VARCHAR2, lockmode IN INTEGER DEFAULT X_MODE, timeout IN NUMBER DEFAULT MAXWAIT, release_on_commit IN BOOLEAN DEFAULT FALSE) RETURN integer; The function returns the status of the attempt to obtain the lock; the codes are identical to those shown above for the convert function. C.7.5 The SLEEP procedureThe SLEEP procedure suspends the current session for a specified period of time (in seconds). The specification is: PROCEDURE DBMS_LOCK.SLEEP (seconds IN NUMBER); Copyright (c) 2000 O'Reilly & Associates. All rights reserved. |
|