The ALLOCATE_UNIQUE_AUTONOMOUS stored procedure is used to apply for a user lock with the lock name specified by lockname. When a lock is requested for the first time, the lock generated is recorded in the DBMS_LOCK_ALLOCATED table and a lock handle is returned. If the corresponding record already exists, only the lock handle is returned, indicating that the two applications correspond to the same lock.
A user lock expires after a period of time specified by expiration_secs. Upon expiration, the corresponding record in the DBMS_LOCK_ALLOCATED table is deleted. Another lock will be returned for a call to ALLOCATE_UNIQUE_AUTONOMOUS with the same name.
Applicability
This topic applies only to OceanBase Database Enterprise Edition. OceanBase Database Community Edition provides only the MySQL mode.
Syntax
DBMS_LOCK.ALLOCATE_UNIQUE_AUTONOMOUS (
lockname IN VARCHAR2,
lockhandle OUT VARCHAR2,
expiration_secs IN INTEGER DEFAULT 864000);
Parameters
| Parameter | Description |
|---|---|
| lockname | The lock name. Do not use lock names beginning with ORA$. |
| lockhandle | Returns the lock handle generated by ALLOCATE_UNIQUE_AUTONOMOUS. You can use this handle in subsequent calls to REQUEST. Lock handles obtained by any session by calling ALLOCATE_UNIQUE_AUTONOMOUS with the same lock name point to the same lock. lockhandle can be up to VARCHAR2 (128). |
| expiration_secs | The number of seconds to wait after the last ALLOCATE_UNIQUE_AUTONOMOUS has been performed on a specified lock, before that lock can be deleted from the DBMS_LOCK_ALLOCATED table. The default waiting period is 10 days. We recommend that you do not delete locks from the DBMS_LOCK_ALLOCATED table, because subsequent calls to ALLOCATE_UNIQUE_AUTONOMOUS will automatically delete expired locks. |
Exceptions
The following error message may be returned: ORA-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