Purpose
You can use this statement to lock one or more tables, partitions, or subpartitions in specified mode.
A locked table remains locked until the transaction is committed, rolled back, or rolled back to the savepoint before the table is locked.
Note
The table to be locked must be in your own schema, or you must have the LOCK ANY TABLE privilege.
Syntax
LOCK TABLE [ schema. ] table_name
IN lock_mode MODE
[ NOWAIT
| WAIT integer
] ;
Parameters
| Parameter | Description |
|---|---|
| table_name | The name of the table to be locked. |
| lock_mode | The lock mode. The current version of OceanBase Database supports the following lock modes:
|
| NOWAIT | This keyword instructs the database to immediately return the control to you if a lock contention occurs when you attempt to lock a table, partition, or subpartition. In this case, the database returns a message indicating that the table, partition, or subpartition is locked by another user. |
| WAIT | This keyword instructs the database to wait for the release of the lock until timeout if a lock contention occurs. The value of integer is not limited. Note: The current version of OceanBase Database does not support the NOTWAIT or WAIT keyword. The timeout period of the statement or transaction, whichever is shorter, is used. That is, the statement waits for the lock until the statement or transaction times out. |
Examples
Lock the tbl1 table in EXCLUSIVE mode, without waiting if another user has locked the table.
obclient> LOCK TABLE tbl1 IN EXCLUSIVE MODE NOWAIT;
Query OK, 0 row affected