Oracle9i Supplied PL/SQL Packages and Types Reference Release 2 (9.2) Part Number A96612-01 |
|
DBMS_LOCK , 2 of 3
This procedure allocates a unique lock identifier (in the range of 1073741824 to 1999999999) given a lock name. Lock identifiers are used to enable applications to coordinate their use of locks. This is provided because it may be easier for applications to coordinate their use of locks based on lock names rather than lock numbers.
If you choose to identify locks by name, you can use ALLOCATE_UNIQUE
to generate a unique lock identification number for these named locks.
The first session to call ALLOCATE_UNIQUE
with a new lock name causes a unique lock ID to be generated and stored in the dbms_lock_allocated
table. Subsequent calls (usually by other sessions) return the lock ID previously generated.
A lock name is associated with the returned lock ID for at least expiration_secs
(defaults to 10 days) past the last call to ALLOCATE_UNIQUE
with the given lock name. After this time, the row in the dbms_lock_allocated
table for this lock name may be deleted in order to recover space. ALLOCATE_UNIQUE
performs a commit.
Caution: Named user locks may be less efficient, because Oracle uses SQL to determine the lock associated with a given name. |
DBMS_LOCK.ALLOCATE_UNIQUE ( lockname IN VARCHAR2, lockhandle OUT VARCHAR2, expiration_secs IN INTEGER DEFAULT 864000);
ORA-20000
, ORU-10003:
Unable to find or insert lock <lockname
> into catalog dbms_lock_allocated
.
This function requests a lock with a given mode. REQUEST
is an overloaded function that accepts either a user-defined lock identifier, or the lock handle returned by the ALLOCATE_UNIQUE
procedure.
DBMS_LOCK.REQUEST( id IN INTEGER || lockhandle IN VARCHAR2, lockmode IN INTEGER DEFAULT X_MODE, timeout IN INTEGER DEFAULT MAXWAIT, release_on_commit IN BOOLEAN DEFAULT FALSE, RETURN INTEGER;
The current default values, such as X_MODE
and MAXWAIT
, are defined in the DBMS_LOCK
package specification.
Return Value | Description |
---|---|
0 |
Success |
1 |
Timeout |
2 |
Deadlock |
3 |
Parameter error |
4 |
Already own lock specified by |
5 |
Illegal lock handle |
This function converts a lock from one mode to another. CONVERT
is an overloaded function that accepts either a user-defined lock identifier, or the lock handle returned by the ALLOCATE_UNIQUE
procedure.
DBMS_LOCK.CONVERT( id IN INTEGER || lockhandle IN VARCHAR2, lockmode IN INTEGER, timeout IN NUMBER DEFAULT MAXWAIT) RETURN INTEGER;
Return Value | Description |
---|---|
0 |
Success |
1 |
Timeout |
2 |
Deadlock |
3 |
Parameter error |
4 |
Don't own lock specified by |
5 |
Illegal lock handle |
This function explicitly releases a lock previously acquired using the REQUEST
function. Locks are automatically released at the end of a session. RELEASE
is an overloaded function that accepts either a user-defined lock identifier, or the lock handle returned by the ALLOCATE_UNIQUE
procedure.
DBMS_LOCK.RELEASE ( id IN INTEGER) RETURN INTEGER; DBMS_LOCK.RELEASE ( lockhandle IN VARCHAR2) RETURN INTEGER;
Parameter | Description |
---|---|
id or lockhandle |
User assigned lock identifier, from 0 to 1073741823, or the lock handle, returned by |
Return Value | Description |
---|---|
0 |
Success |
3 |
Parameter error |
4 |
Do not own lock specified by |
5 |
Illegal lock handle |
This procedure suspends the session for a given period of time.
DBMS_LOCK.SLEEP ( seconds IN NUMBER);
Parameter | Description |
---|---|
seconds |
Amount of time, in seconds, to suspend the session. The smallest increment can be entered in hundredths of a second; for example, 1.95 is a legal time value. |
|
Copyright © 2000, 2002 Oracle Corporation. All Rights Reserved. |
|