User locks are automatically released when a session terminates.
Warning: This implementation does not efficiently support more than a few hundred locks per session. Oracle strongly recommends that you develop a standard convention be developed for using these user locks. This avoids conflicts among procedures trying to use the same locks. For example, you might want to include your company name as part of the lock name to ensure that your lock names do not conflict with lock names used in any Oracle supplied applications.
for information on granting the necessary privileges to users who will be executing this package.
Warning: Named user locks may be less efficient, as Oracle uses SQL to determine the lock associated with a given name.
The parameters for the ALLOCATE_UNIQUE procedure are described in Table 3 - 4. The syntax for this procedure is shown below.
DBMS_LOCK.ALLOCATE_UNIQUE(lockname IN VARCHAR2,
lockhandle OUT VARCHAR2,
expiration_secs IN INTEGER
DEFAULT 864000);
The parameters for the REQUEST function are described in Table 3 - 5 and the possible return values and their meanings are described in Table 3 - 6. The syntax for this function is shown below.
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 default values, such as X_MODE and MAXWAIT, are defined in the DBMS_LOCK package specification. See the package specification, available on-line, for the current default values.
| Parameter | Description |
| ID or LOCKHANDLE | Specify the user assigned lock identifier, from 0 to 1073741823, or the lock handle, returned by ALLOCATE_UNIQUE, of the lock whose mode you want to change. |
| LOCKMODE | Specify the mode that you are requesting for the lock. The available modes and their associated integer identifiers are listed below. The abbreviations for these locks, as they appear in the V$ views and Server Manager monitors are shown in parentheses. 1 - null mode 2 - row share mode (ULRS) 3 - row exclusive mode (ULRX) 4 - share mode (ULS) 5 - share row exclusive mode (ULRSX) 6 - exclusive mode (ULX) Each of these lock modes is explained in the Oracle7 Server Concepts manual. |
| TIMEOUT | Specify the number of seconds to continue trying to grant the lock. If the lock cannot be granted within this time period, the call returns a value of 1 (timeout). |
| RELEASE_ON_COMMIT | Set this parameter to TRUE to release the lock on commit or rollback. Otherwise, the lock is held until it is explicitly released or until the end of the session. |
| Return Value | Description |
| 0 | success |
| 1 | timeout |
| 2 | deadlock |
| 3 | parameter error |
| 4 | already own lock specified by ID or LOCKHANDLE |
| 5 | illegal lock handle |
The parameters for the CONVERT function are described in Table 3 - 7 and the possible return values and their meanings are described in Table 3 - 8. The syntax for this function is shown below.
DBMS_LOCK.CONVERT(
id IN INTEGER ||
lockhandle IN VARCHAR2,
lockmode IN INTEGER,
timeout IN NUMBER DEFAULT MAXWAIT)
RETURN INTEGER;
| Parameter | Description |
| ID or LOCKHANDLE | Specify the user assigned lock identifier, from 0 to 1073741823, or the lock handle, returned by ALLOCATE_UNIQUE, of the lock whose mode you want to change. |
| LOCKMODE | Specify the new mode that you want to assign to the given lock. The available modes and their associated integer identifiers are listed below. The abbreviations for these locks, as they appear in the V$ views and Server Manager monitors are shown in parentheses. 1 - null mode 2 - row share mode (ULRS) 3 - row exclusive mode (ULRX) 4 - share mode (ULS) 5 - share row exclusive mode (ULRSX) 6 - exclusive mode (ULX) Each of these lock modes is explained in the Oracle7 Server Concepts manual. |
| TIMEOUT | Specify the number of seconds to continue trying to change the lock mode. If the lock cannot be converted within this time period, the call returns a value of 1 (timeout). |
| Return Value | Description |
| 0 | success |
| 1 | timeout |
| 2 | deadlock |
| 3 | parameter error |
| 4 | don't own lock specified by ID or LOCKHANDLE |
| 5 | illegal lock handle |
The parameters for the RELEASE function are described in Table 3 - 9 and the possible return values and their meanings are described in Table 3 - 10. The syntax for this function is shown below.
DBMS_LOCK.RELEASE(id IN INTEGER) RETURN INTEGER;
DBMS_LOCK.RELEASE(lockhandle IN VARCHAR2) RETURN INTEGER;
| Parameter | Description |
| ID or LOCKHANDLE | Specify the user-assigned lock identifier, from 0 to 1073741823, or the lock handle, returned by ALLOCATE_UNIQUE, of the lock that you want to release. |
| Return Value | Description |
| 0 | success |
| 3 | parameter error |
| 4 | do not own lock specified by ID or LOCKHANDLE |
| 5 | illegal lock handle |
The parameters for the SLEEP procedure are described in Table 3 - 11. The syntax for the SLEEP procedure is shown below.
DBMS_LOCK.SLEEP(seconds IN NUMBER);
| Parameter | Description |
| SECONDS | Specify the 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. |