Skip to Main Content

Breadcrumb

Question and Answer

Tom Kyte

Thanks for the question, Rama Subramanian.

Asked: December 18, 2000 - 9:20 am UTC

Last updated: April 28, 2004 - 3:17 am UTC

Version: 6.0

Viewed 1000+ times

You Asked

Hi Tom,

I'm using Forms Version 6.0.5.0.2 (Developer 2000 Ver.6.0).
My Database is Oracle Ver.8.1.5.

I have a question on Forms.

When I issue an EXECUTE_QUERY(FOR_UPDATE,NO_WAIT) from one of my datablocks, I get a standard message (Two Button Alert) from Forms, as below, if the record I'm trying to access is locked by someone else.

FORMS - Could not reserve record (2 tries) Keep Trying? - Yes/No.

Is there any way by which I can trap this message and issue my own message? Or is there any other way that I can issue an EXECUTE_QUERY(FOR_UPDATE), and notify the user if the record in question is not immediately available?

Regards,
Rama Subramanian G

and Tom said...

You can program your own ON-LOCK trigger on that block that does the equivalent of what forms does. Lets say you have a block on DEPT. You could code an ON-LOCK trigger on that block like:


declare
resource_busy exception;
pragma exception_init( resource_busy, -54 );
l_deptno number;
begin
for i in 1 .. 3
loop
begin
select deptno into l_deptno
from dept
where rowid = :dept.rowid
and deptno = :dept.deptno
and dname = :dept.dname
and loc = :dept.loc
FOR UPDATE NOWAIT;

RETURN;
exception
when resource_busy then
null;
when no_data_found then
message( 'Sorry, row was changed by some other
session, please requery it' );
end;
end loop;

message( 'Bummer, someone else has this locked!!!!' );
raise form_trigger_failure;
end;


The logic is basically the same as what forms does for you automatically. It'll try to query the row up with a FOR UPDATE NOWAIT by rowid using all of the values in the block. If we get resource_busy, someone has it locked -- try again. If we get no data found -- the rows values have changed since we queried it -- you lose. Otherwise we return and the record is locked by our session. After trying three times -- we'll give up and return our own message about the row being locked.



Rating

  (2 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

execute_query(for_update,nowait)

Steve Marrochello, January 23, 2002 - 9:57 am UTC

Is there anyway to display which user might have a lock on the records you are trying to query for an update. We have problems with careless users just going on lunch breaks without exiting their application. Somebody who tries to access those records would like to see who is locking the records so that they can have somebody exit out the offending machine.

Tom Kyte
January 23, 2002 - 6:20 pm UTC

Well, the DBA can see it -- you have to be blocked in order to see the blocker. You can generate a LIST of CANDIDATES and see who's been idle the longest (they are the best candidate). You would use v$lock to see whose got TM locks on your objects and then v$session to see whose been idle for a while.

lock

omer, April 28, 2004 - 3:17 am UTC

Hi!
my question is on locks in forms. I am using developer 6
I have a application in which
A is main form,
which calls B,
B calls C,
C calls D
(all using call form)
A, B and C are just intro form.
in D, I update record, then i go to sql, write update on the same row in table used in D form. press slash, sql is waiting because same record is locked by D form.
then I exit the D form, form ask for changes to save
i select no, form exits.
the locks should be released at this time
but on sql, it is still waiting.
then i closed the whole application first C, B and A.
now sql has updated that record
my question is why locks are not released when i exit the form D, but locks are released when i close the whole application?
thanks

More to Explore

PL/SQL demos

Check out more PL/SQL tutorials on our LiveSQL tool.

PL/SQL docs

PL/SQL reference manual from the Oracle documentation library