Re: How to lock record in pl/sql?
From: Pete Kolton <Pete_at_nospam.kolton.com>
Date: 1997/12/18
Message-ID: <01bd0b4a$b3035f30$c53c63c3_at_dan01>#1/1
e_record_locked exception;
pragma exception_init (e_record_locked, -54);
Pete Kolton
ORACLE Systems Consultant
All reasonable offers considered :-)
Received on Thu Dec 18 1997 - 00:00:00 CET
Date: 1997/12/18
Message-ID: <01bd0b4a$b3035f30$c53c63c3_at_dan01>#1/1
Robert Augustyn <augustyn_at_unn.unisys.com> wrote in article
<676ds4$llf$1_at_mail.pl.unisys.com>...
> Hi,
> I need to read and update the record so I need to lock it,
> How do one do that?
declare
--PRAGMA MAPS ORACLE ERROR CODE TO SPECIFIC EXCEPTION --IN THIS CASE, ERROR 54 MEANS RECORD LOCKED AND NOWAIT --SPECIFIED.
e_record_locked exception;
pragma exception_init (e_record_locked, -54);
v_field_name table_name.field_name %type;
--SELECT FOR UPDATE LOCKS THE RECORD --USE NOWAIT SO THAT YOU DON'T WAIT FOR ANOTHER --USER TO RELEASE THE RECORD. cursor c1 is select field_name from table_name for update nowait;
begin
open c1;
fetch c1
into v_field_name;
update.....
blah! blah!
exception
when e_record_locked then
--HANDLE THE ERROR HERE (MESSAGE IF IN FORMS ETC.)
Pete Kolton
ORACLE Systems Consultant
All reasonable offers considered :-)
mailto:Pete_at_kolton.com
http://www.kolton.com
Received on Thu Dec 18 1997 - 00:00:00 CET