The ALLOCATE_UNIQUE_AUTONOMOUS procedure is used to request a user lock, and the user needs to specify the lock name lockname. On the first request, the allocated lock will be recorded in the DBMS_LOCK_ALLOCATED table, and the lockhandle will be returned. On subsequent requests, if a record already exists, the Lock Handle will be returned directly, indicating that the same lock is being used.
User locks have an expiration time specified by expiration_secs. After the expiration time, the corresponding record in the DBMS_LOCK_ALLOCATED table will be deleted. When requesting the same lock name again, a new lock will be allocated, which is unrelated to the previous lock.
Applicability
This topic applies only to OceanBase Database Enterprise Edition. OceanBase Database Community Edition does not support this feature.
Syntax
DBMS_LOCK.ALLOCATE_UNIQUE_AUTONOMOUS (
lockname IN VARCHAR2,
lockhandle OUT VARCHAR2,
expiration_secs IN INTEGER DEFAULT 864000);
Parameters
| Parameter | Description |
|---|---|
| lockname | The name of the lock. Note that it should not start with ORA$. |
| lockhandle | The lock handle returned by the ALLOCATE_UNIQUE_AUTONOMOUS procedure, which can be used for REQUEST operations. Any session that obtains the same lock name through ALLOCATE_UNIQUE_AUTONOMOUS will point to the same lock. The maximum length of lockhandle is VARCHAR2 (128). |
| expiration_secs | Specifies the retention time for the lock records in the DBMS_LOCK_ALLOCATED table. During this period, the corresponding lock mapping will not be cleared. The default timeout is 10 days. ALLOCATE_UNIQUE_AUTONOMOUS automatically clears expired locks, so you should not manually delete data from the DBMS_LOCK_ALLOCATED table. |
Error messages
The error message is as follows: OBE-20000, ORU-10003: Unable to find or insert lock <lockname> into catalog dbms_lock_allocated.
Examples
obclient> DELIMITER /
obclient> DECLARE
my_lockname VARCHAR2(100) :='test01';
my_lockhandle VARCHAR2(200);
BEGIN
DBMS_LOCK.ALLOCATE_UNIQUE_AUTONOMOUS(lockname => my_lockname,lockhandle => my_lockhandle);
END;/
Query OK, 1 row affected
