The REQUEST stored procedure is used to obtain a lock in a specified lock mode by specifying a lock ID or a 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 to obtain. |
| timeout |
The time to wait for a lock conflict, in seconds. If the timeout occurs, 1 is returned. |
| release_on_commit |
If set to TRUE, the lock is released when the transaction is committed or rolled back. Otherwise, the lock is retained until it is explicitly released or the session is disconnected. In the current version, this parameter supports TRUE and FALSE. The default value is FALSE. Currently, when release_on_commit = TRUE, the lock cannot be released using the RELEASE subprogram. |
Return values
| Return value |
Description |
| 0 |
The operation was successful. |
| 1 |
The operation timed out. |
| 2 |
A deadlock occurred. |
| 3 |
An invalid parameter was specified. |
| 4 |
The lock is already held. |
| 5 |
The lock handle is invalid. |
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