Cursor Batch Processing With Update

@@@cursor bathch processing with update
HR@ocp> ed
Wrote file afiedt.buf
  1  DECLARE
  2    CURSOR cur_emp(emp_id NUMBER) IS
  3     SELECT * FROM emp
  4     WHERE employee_id=emp_id
  5     FOR UPDATE OF stars NOWAIT;
  6    cur_r_emp   cur_emp%ROWTYPE;
  7  BEGIN
  8    OPEN cur_emp( &emp_id );
  9    LOOP
 10    FETCH cur_emp INTO cur_r_emp;
 11    EXIT WHEN cur_emp%NOTFOUND OR cur_emp%NOTFOUND is null;
 12      UPDATE emp SET stars=LPAD('*',round(cur_r_emp.salary/1000),'*')
 13      WHERE CURRENT OF cur_emp;
 14    END LOOP;
 15    CLOSE cur_emp;
 16* END;
HR@ocp> /
Enter value for emp_id: 100
old   8:   OPEN cur_emp( &emp_id );
new   8:   OPEN cur_emp( 100 );
PL/SQL procedure successfully completed.

你可能感兴趣的:(update,Cursor)