Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: How to lock a row when the row is not is accessed
li.js_at_neusoft.com wrote:
> I want to lock some rows in a table, but I must know these rows are not
> accessed(SELECT/UPDATE) by other sessions.
>
> How to know the row is used by other sessions.
SELECT .. FOR UPDATE NOWAIT This will select the rows and lock them for UPDATE - but should they already be locked the SELECT statement will raise an exception.
Or you can add the WAIT clause with the number of seconds to wait for the rows to be unlocked (i.e. available for updating) before timing out.
Also note that locking rows does not block readers - other sessions can still read the rows as per Oracle MVCC (Multi Version Concurrency Control) model.
You can also skip locked rows using the SKIP LOCKED clause.
-- BillyReceived on Thu Jun 16 2005 - 06:02:11 CDT