如何使用WHERE CURRENT OF更新游标记录?

时间:2012-11-03 08:22:12

标签: oracle plsql cursor

执行此块时,我收到“ORA-01410:无效的ROWID”异常。有什么想法吗?

DECLARE
  CURSOR c_orders IS
    SELECT * from orders FOR UPDATE OF no;
  v_order_record c_orders%ROWTYPE;
BEGIN
  OPEN c_orders; 
  LOOP
    FETCH c_orders INTO v_order_record;
    UPDATE orders SET no = 11 WHERE CURRENT OF c_orders;
    EXIT WHEN c_orders%NOTFOUND; 
  END LOOP;  
  CLOSE c_orders; 
END; 

但是,如果使用FOR IN语法,一切都有效:

DECLARE
  CURSOR c_orders IS
    SELECT * from orders FOR UPDATE OF no;
BEGIN
  FOR rec IN c_orders
  LOOP
    UPDATE orders SET no = 11 WHERE CURRENT OF c_orders;
  END LOOP; 
END; 

1 个答案:

答案 0 :(得分:4)

exit when移至update之前 - 您无法更新不存在的内容。