Question

I am in bit confusion regarding update lock, in the below program

CREATE OR REPLACE
PROCEDURE pro_cedure(
    p_dept_id NUMBER )
IS
  CURSOR mycursor
  IS
    SELECT deptno,comm,extra
    FROM emp
    WHERE comm IS NULL
    AND extra  IS NOT NULL
    AND deptno  = p_dept_id 
    FOR UPDATE OF comm;
BEGIN
  FOR emp_rec IN mycursor
  LOOP
    UPDATE emp SET comm = extra 
    WHERE CURRENT OF mycursor;
    INSERT INTO changed
      (
        deptno,
        oldval,
        newval,
        seq_nextval
      )
      VALUES
      (
        emp_rec.deptno,
        emp_rec.comm,
        emp_rec.extra,
        sequence_name.nextval
      );
  END LOOP;
END; 

if some other user try to update the same table or the same row while I am updating does it causes a lock with this program?

Was it helpful?

Solution

If you run this procedure 2 times parallel, the second wont execute the select until the first commits. (Of course if you run other statements with the same for update of comm clause they will be queued the same way.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top