The REQUEST stored procedure is used to obtain a lock in a specified lock mode with a lock ID or lock handle.
Syntax
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;
Parameters
| Parameter |
Description |
| id || lockhandle |
The lock ID or lock handle. |
| lockmode |
The lock mode requested. |
| timeout |
The number of seconds to wait for a return result in the case of lock contention. If the lock cannot be granted within this time period, the call returns 1. |
| release_on_commit |
Set the value to TRUE to release the lock on commit or rollback. Otherwise, the lock is held until it is explicitly released or until the session is disconnected. In the current version, this parameter can only be set to TRUE. At present, you cannot use the RELEASE subprogram to release a lock when release_on_commit is set to TRUE. |
Return values
| Return value |
Description |
| 0 |
The operation was successful. |
| 1 |
A timeout occurred. |
| 2 |
A deadlock occurred. |
| 3 |
A parameter error occurred. |
| 4 |
A lock has been used. |
| 5 |
Invalid lock handle. |
Examples
obclient> DELIMITER /
obclient> DECLARE
my_lockname VARCHAR2(100) :='test01';
my_lockhandle VARCHAR2(200);
my_lock_output NUMBER;
BEGIN
DBMS_LOCK.ALLOCATE_UNIQUE(lockname => my_lockname,lockhandle => my_lockhandle);
my_lock_output := DBMS_LOCK.REQUEST(my_lockhandle,6, 60, FALSE);
END;/
Query OK, 1 row affected