Question : Oracle locks

Dear Expert,
    Iam working in multiple user environment.
   I was exposed to a procedure down below to fix a lock.
  But i couldn't understand why rollback is there in the exception part.Can anybody explain to me.

DECLARE
 l_count                 NUMBER :=0;
 e_locked                EXCEPTION;
 e_no_data               EXCEPTION;
 PRAGMA EXCEPTION_INIT(e_locked, -54);
 CURSOR c1 IS SELECT 1
    FROM co_details
        WHERE co_id = 1184 AND quantity > 1 FOR UPDATE NOWAIT;
 BEGIN
   FOR c2 IN c1 LOOP
      l_count := l_count +1 ;
   END LOOP;
 
  IF l_count = 0 THEN
     RAISE e_no_data;
  END IF;
EXCEPTION
  WHEN  e_locked THEN
     DBMS_OUTPUT.put_line('Co number is locked');
     ROLLBACK;
  WHEN e_no_data THEN
      DBMS_OUTPUT.put_line('No data found');
      ROLLBACK;
END;

Thanks,

Answer : Oracle locks

FOR UPDATE NOWAIT ; --if this statement raises or in general if there is any error, then exception will get raised in your code for no data found or e_locked and then rollback all DML changes what ever has happened after the last commit.

I believe there should be some DML in your code.. like insert/update/delete/merge...did you remove them before posting here.
Random Solutions  
 
programming4us programming4us