explicit locking
Hi All
I have a button on a form, when this button is clicked it should read a value from the form and sum it to the total value in a table , here are the steps for When-button-pressed trigger :
1- Read the total issued quantity form the master table and lock the row :
select ISSUED_QTY INTO V_LOCK_QTY
from stopen
where STOCK_CODE=:ISSLINES.STOCK_CODE
for update NOWAIT;
2- Add the value in the form to issued_qty colum in that table:
UPDATE STOPEN
SET ISSUED_QTY=NVL(ISSUED_QTY,0)+NVL(:ISSLINES.QTY,0)
where STOCK_CODE=:ISSLINES.STOCK_CODE;
I used the for update clause to lock the row that was read in step 1 and will be updated in step 2 to make sure that no other user can update that row untill the current user update it and commit (or rollback).
My question is :
1- Is this type of locking is suitable to this situation ?
2- How can I Handle the exception if that row was locked by another user ? by a message with 2 options (wait or exit the trigger).
3- How can I lock the row for a limited time ,I tried to write : for update WAIT 5, but forms cosidered it as syntax error.
Thanks in advance
Mostafa